-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpillbot.py
50 lines (49 loc) · 1.77 KB
/
pillbot.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
import subprocess
import pigpio
import time
import RPi.GPIO as GPIO
#subprocess.run('tmux new-session -d -s "displayscript1" /home/pillbot/Desktop/facedisplay.sh'.split())
small = int(input("How many small pills?: "))
large = int(input("How many large pills?: "))
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.IN)
start = time.time()
#numpills = 2
pi = pigpio.pi()
subprocess.run('tmux new-session -d -s displayscript2 /home/pillbot/Desktop/facedisplay2.sh'.split())
time.sleep(4)
pi.set_servo_pulsewidth(18, 1430)
#pi.set_servo_pulsewidth(12, 1430)
for x in range(0, small):
while GPIO.input(21) == 0:
if time.time() - start > 5 and time.time() - start < 5.3:
pi.set_servo_pulsewidth(18, 2000)
#pi.set_servo_pulsewidth(12, 2000)
if time.time() - start > 5.3:
pi.set_servo_pulsewidth(18, 1430)
#pi.set_servo_pulsewidth(12, 1430)
start = time.time()
while GPIO.input(21) == 1:
pi.set_servo_pulsewidth(18, 0)
#pi.set_servo_pulsewidth(12, 0)
time.sleep(0.2)
pi.set_servo_pulsewidth(18, 0)
start = time.time()
pi.set_servo_pulsewidth(12, 1420)
for x in range(0, large):
while GPIO.input(21) == 0:
if time.time() - start > 5 and time.time() - start < 5.3:
#pi.set_servo_pulsewidth(18, 2000)
pi.set_servo_pulsewidth(12, 2000)
if time.time() - start > 5.3:
#pi.set_servo_pulsewidth(18, 1430)
pi.set_servo_pulsewidth(12, 1420)
start = time.time()
while GPIO.input(21) == 1:
#pi.set_servo_pulsewidth(18, 0)
pi.set_servo_pulsewidth(12, 0)
time.sleep(0.2)
pi.set_servo_pulsewidth(18, 0)
pi.set_servo_pulsewidth(12, 0)
subprocess.run('tmux kill-session -t displayscript2'.split())
pi.stop()