Skip to content

Commit

Permalink
making light pwm (#68)
Browse files Browse the repository at this point in the history
Co-authored-by: unknown <[email protected]>
  • Loading branch information
Aask42 and unknown authored Apr 5, 2022
1 parent e11b087 commit 0988524
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions duckyinpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,25 @@
import time
import digitalio
from board import *
led = digitalio.DigitalInOut(LED)
led.direction = digitalio.Direction.OUTPUT
import pwmio

led = pwmio.PWMOut(LED, frequency=5000, duty_cycle=0)

def led_pwm_up(led):
for i in range(100):
# PWM LED up and down
if i < 50:
led.duty_cycle = int(i * 2 * 65535 / 100) # Up
time.sleep(0.01)
def led_pwm_down(led):
for i in range(100):
# PWM LED up and down
if i >= 50:
led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down
time.sleep(0.01)

# led = digitalio.DigitalInOut(LED)
# led.direction = digitalio.Direction.OUTPUT

duckyCommands = {
'WINDOWS': Keycode.WINDOWS, 'GUI': Keycode.GUI,
Expand Down Expand Up @@ -109,8 +126,7 @@ def parseLine(line):
# sleep at the start to allow the device to be recognized by the host computer
time.sleep(.5)

led.value = True

led_pwm_up(led)

def getProgrammingStatus():
# check GP0 for setup mode
Expand Down Expand Up @@ -198,8 +214,12 @@ def selectPayload():
else:
print("Update your payload")

led_state = False
while True:
time.sleep(1.0)
led.value = False
time.sleep(1.0)
led.value = True
if led_state:
led_pwm_up(led)
led_state = False
else:
led_pwm_down(led)
led_state = True

0 comments on commit 0988524

Please sign in to comment.