Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # blink_led.py
  3. # gpio test code for pcduino ( http://www.pcduino.com )
  4. #
  5. import gpio
  6. import time
  7.  
  8. led_pin = "gpio6"
  9. led_pin2 = "gpio7"
  10. led_pin3 = "gpio8"
  11. #led_pin4 = "gpio9"
  12. pins = []
  13. pins.append(led_pin)
  14. pins.append(led_pin2)
  15. pins.append(led_pin3)
  16. #pins.append(led_pin4)
  17. pin_led_states = [
  18. [1, 0, -1], # A
  19. [0, 1, -1], # B
  20. [-1, 1, 0], # C
  21. [-1, 0, 1], # D
  22. [1, -1, 0], # E
  23. [0, -1, 1] # F
  24. ]
  25. def delay(ms):
  26. time.sleep(1.0*ms/1000)
  27. def set_pin(pin_index, pin_state):
  28. if pin_state == -1:
  29. gpio.pinMode(pins[pin_index], gpio.INPUT)
  30. else:
  31. gpio.pinMode(pins[pin_index], gpio.OUTPUT)
  32. gpio.digitalWrite(pins[pin_index], pin_state)
  33. def light_led(led_number):
  34. for pin_index, pin_state in enumerate(pin_led_states[led_number]):
  35. set_pin(pin_index, pin_state)
  36. def unsetpins():
  37. for x in range(0,len(pins)-1):
  38. set_pin(x, -1)
  39. unsetpins()
  40. x=0
  41. while True:
  42. #x = int(raw_input("Pin (0 to 5):"))
  43. if x<= 6:
  44. #light_led(x)
  45. light_led(x%6)
  46. delay(50)
  47. else:
  48. break
  49. x=x+1
  50. unsetpins()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement