Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def read_pins():
- pins = {
- 0 : pfio.digital_read(0),
- 1 : pfio.digital_read(1),
- 2 : pfio.digital_read(2),
- 3 : pfio.digital_read(3),
- 4 : pfio.digital_read(4),
- 5 : pfio.digital_read(5),
- 6 : pfio.digital_read(6),
- 7 : pfio.digital_read(7)
- }
- return pins
- def check_input_changes(prev, curr):
- i = 0
- changes = []
- while i < 8:
- if prev[i] == curr[i]:
- pass
- # no change, do nothing
- elif (prev[i] > curr[i]):
- chg = {
- "pin" : i,
- "change" : "off"
- }
- changes.append(chg)
- elif (prev[i] < curr[i]):
- chg = {
- "pin" : i,
- "change" : "on"
- }
- changes.append(chg)
- i = i + 1
- change_report = {
- "time" : time.time(),
- "changes" : changes,
- "diff" : len(changes)
- }
- return change_report
- if __name__ == '__main__':
- pfio.init()
- pins = {
- 0 : 0,
- 1 : 0,
- 2 : 0,
- 3 : 0,
- 4 : 0,
- 5 : 0,
- 6 : 0,
- 7 : 0
- }
- while True:
- prev_pins = pins
- pins = read_pins()
- change_report = check_input_changes(prev_pins, pins)
- time.sleep(.05)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement