-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight_pwm.py
More file actions
35 lines (28 loc) · 738 Bytes
/
light_pwm.py
File metadata and controls
35 lines (28 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
import wiringpi as wpi
pPWM = 26
pwmMinOn = 490
pwmMaxOn = 1024
pwmOn = 0
pwmValue = 800
def setup():
print "Setup Starting"
wpi.wiringPiSetup()
wpi.pinMode(pPWM, wpi.PWM_OUTPUT)
wpi.pwmWrite(pPWM, 0)
def loop():
global pwmValue
while True:
pwmIn = input("0,490-1024: ")
pwmValue = int(pwmIn)
if pwmValue < pwmMinOn:
pwmValue = 0
if pwmValue > pwmMaxOn:
pwmValue = pwmMaxOn
wpi.pwmWrite(pPWM, pwmValue)
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
print "Ended"