Skip to content

Commit 0988524

Browse files
Aask42unknown
and
unknown
authored
making light pwm (#68)
Co-authored-by: unknown <[email protected]>
1 parent e11b087 commit 0988524

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

duckyinpython.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,25 @@
1919
import time
2020
import digitalio
2121
from board import *
22-
led = digitalio.DigitalInOut(LED)
23-
led.direction = digitalio.Direction.OUTPUT
22+
import pwmio
23+
24+
led = pwmio.PWMOut(LED, frequency=5000, duty_cycle=0)
25+
26+
def led_pwm_up(led):
27+
for i in range(100):
28+
# PWM LED up and down
29+
if i < 50:
30+
led.duty_cycle = int(i * 2 * 65535 / 100) # Up
31+
time.sleep(0.01)
32+
def led_pwm_down(led):
33+
for i in range(100):
34+
# PWM LED up and down
35+
if i >= 50:
36+
led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down
37+
time.sleep(0.01)
38+
39+
# led = digitalio.DigitalInOut(LED)
40+
# led.direction = digitalio.Direction.OUTPUT
2441

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

112-
led.value = True
113-
129+
led_pwm_up(led)
114130

115131
def getProgrammingStatus():
116132
# check GP0 for setup mode
@@ -198,8 +214,12 @@ def selectPayload():
198214
else:
199215
print("Update your payload")
200216

217+
led_state = False
201218
while True:
202-
time.sleep(1.0)
203-
led.value = False
204-
time.sleep(1.0)
205-
led.value = True
219+
if led_state:
220+
led_pwm_up(led)
221+
led_state = False
222+
else:
223+
led_pwm_down(led)
224+
led_state = True
225+

0 commit comments

Comments
 (0)