Commit 94057a6e authored by Hugo Hornquist's avatar Hugo Hornquist

initial commit

parents
import RPi.GPIO as g
g.setmode(g.BCM)
g.setup(22, g.IN)
print g.input(22)
#!/usr/bin/env python2
import RPi.GPIO as g
g.setmode(g.BCM)
g.setup(17, g.IN)
g.setup(18, g.OUT)
input_value = g.input(17)
print input_value
#g.output(18, g.HIGH)
#!/usr/bin/env python2
import RPi.GPIO as g
g.setmode(g.BOARD)
g.setup(11, g.IN)
g.setup(12, g.OUT)
input_value = g.input(11)
g.output(12, g.HIGH)
#!/usr/bin/env python2
import RPi.GPIO as g
import time
g.setmode(g.BCM)
# pins = range(0, 26)
# for pin in pins:
# g.setup(pin, g.IN)
pins = [ 5, 6 ]
# while True:
# #for pin in pins:
# input = g.input(pin)
# if input:
# print "pin {0} is high".format(pin)
def callback_rise(pin):
print "rise", pin
def callback_fall(pin):
print "fall", pin
for pin in pins:
g.setup(pin, g.IN)
g.add_event_detect(pin, g.RISING, callback=callback_rise)
#g.add_event_detect(pin, g.FALLING, callback=callback_fall)
time.sleep(1000)
#!/usr/bin/env python2
import RPi.GPIO as g
import time
import threading
# For lazer array
# if no bottle present then all are high
# if bottle at least one low
# For regular button
# Down means bottle
# up means no bottle
g.setmode(g.BCM)
pins = [ 17 ]
btn_pin = 22
def callback(pin):
state = g.input(pin)
if state == g.LOW:
fallwait.set()
else:
risewait.set()
g.setup(btn_pin, g.IN, pull_up_down=g.PUD_DOWN)
for pin in pins:
g.setup(pin, g.IN, pull_up_down=g.PUD_DOWN)
g.add_event_detect(pin, g.BOTH, callback=callback)
risewait = threading.Event()
fallwait = threading.Event()
def bottle_check(pins):
return not all([g.input(pin) for pin in pins])
class States:
no_hafv = 0
hafv_ready = 1
hafv_active = 2
has_bottle = bottle_check(pins)
state = States.no_hafv
start_time = 0
end_time = 0
def time_ms():
t = int(time.time() * 1000)
# print "Time: ", t
return t
if has_bottle:
state = States.hafv_ready
def wait_rise():
risewait.clear()
risewait.wait()
def wait_fall():
fallwait.clear()
fallwait.wait()
# should these be the other way around?
def wait_for_bottle_place():
#return wait_rise()
return wait_fall()
def wait_for_bottle_remove():
#return wait_fall()
return wait_rise()
while True:
if state == States.no_hafv:
print
print "Inget Hafv"
wait_for_bottle_place()
state = States.hafv_ready
elif state == States.hafv_ready:
print "Hafv redo"
out = g.wait_for_edge(btn_pin, g.RISING)
state = States.hafv_active
start_time = time_ms()
elif state == States.hafv_active:
print "currently Hafving"
if not bottle_check(pins):
print "Early start"
state = States.no_hafv
continue
print "Raise the bottle"
wait_for_bottle_remove()
print "BOTTLE RAISED"
print "Place back bottle after hafv"
wait_for_bottle_place()
print "BOTTLE PLACED"
end_time = time_ms()
t = (end_time - start_time) / 1000.0
print "Hafvtid: {0} s".format(t)
state = States.no_hafv
time.sleep(1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment