-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paththreadTest.py
38 lines (29 loc) · 856 Bytes
/
threadTest.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
from threading import Thread
import time
import pigpio as pg
RPi = pg.pi()
laserClockPin = 12
def main_loop():
laserthread = LaserSim()
laserthread.start()
time.sleep(20) # execute while loop for 20 seconds
laserthread.stop()
class LaserSim(Thread):
def __init__(self):
super(LaserSim, self).__init__()
self.pins = [17,22,27,24]
self._keepgoing = True
def run(self):
RPi.set_pull_up_down(laserClockPin,pg.PUD_DOWN)
RPi.hardware_PWM(laserClockPin,1250,500000)
while (self._keepgoing):
for pin in self.pins:
RPi.write(pin,1)
time.sleep(0.25)
RPi.write(pin,0)
def stop(self):
self._keepgoing = False
RPi.write(laserClockPin,0)
for pin in self.pins:
RPi.write(pin,0)
main_loop()