-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwm.py
73 lines (59 loc) · 1.3 KB
/
pwm.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#Define Libraries
import RPi.GPIO as gpio
import time
#Configuring don’t show warnings
gpio.setwarnings(False)
#Configuring GPIO
gpio.setmode(gpio.BOARD)
gpio.setup(33,gpio.OUT)
gpio.setup(35,gpio.OUT)
gpio.setup(38,gpio.OUT)
gpio.setup(40,gpio.OUT)
#Configure the pwm objects and initialize its value
pwmMot1 = gpio.PWM(38,100)
pwmMot1.start(0)
pwmMot2 = gpio.PWM(33,100)
pwmMot2.start(0)
pwmMot3 = gpio.PWM(35,100)
pwmMot3.start(0)
pwmMot4 = gpio.PWM(40,100)
pwmMot4.start(0)
#Create the dutycycle variables
dc1 = 0
dc2 = 0
dc3 = 0
dc4 = 0
#Loop infinite
while True:
#increment gradually the luminosity
pwmMot1.ChangeDutyCycle(dc1)
time.sleep(0.05)
dc1 = dc1 + 1
if dc1 == 100:
dc1 = 0
#increme'nt gradually the luminosity
pwmMot1.ChangeDutyCycle(dc1)
time.sleep(0.05)
dc1 = dc1 + 1
if dc1 == 100:
dc1 = 0
#increment gradually the luminosity
pwmMot2.ChangeDutyCycle(dc2)
time.sleep(0.05)
dc2 = dc2 + 1
if dc2 == 100:
dc2 = 0
#increment gradually the luminosity
pwmMot3.ChangeDutyCycle(dc3)
time.sleep(0.05)
dc3 = dc3 + 1
if dc3 == 100:
dc3 = 0
pwmMot4.ChangeDutyCycle(dc3)
time.sleep(0.05)
dc3 = dc3 + 1
if dc3 == 100:
dc3 = 0
#End code
gpio.cleanup()
exit()