1. #!/usr/bin/env python
  2. # Must be run as root - sudo python blink_cylon.py
  3. import RPi.GPIO as GPIO
  4. import time
  5. def setup( led ):
  6. GPIO.setup( led, GPIO.OUT );
  7. return;
  8. def Liga( led, onoff, wait):
  9. LED = GPIO.output( led, onoff ); time.sleep(wait);
  10. return;
  11. def Padrao( padrao, wait):
  12. for i in range( 0, 8):
  13. Liga( LEDs[i] , int(padrao[i]), 0 )
  14. time.sleep(wait);
  15. return;
  16. #Estes sao os PINs em modo BOARD
  17. LEDs = [7, 11, 12, 13, 15, 16, 18, 22]
  18. #Estes sao os PINs em modo BCM
  19. #LEDs = [4, 17, 18, 27, 22, 23, 24, 25]
  20. Delay = [0.15, 0.07]
  21. BOTAO = 23 #not set yet ...
  22. GPIO.cleanup();
  23. #GPIO.setmode (GPIO.BCM );
  24. GPIO.setmode (GPIO.BOARD );
  25. ON = GPIO.HIGH; OFF = GPIO.LOW
  26. for a in LEDs: setup( a )
  27. for a in LEDs: Liga( a , ON, 0 )
  28. time.sleep(1)
  29. for a in LEDs: Liga( a , OFF, 0 )
  30. #Testar padrao
  31. Padrao( "11111111", 1)
  32. Padrao( "00000000", 1)
  33. while True:
  34. i=0;
  35. Padrao( "10000000", Delay[1])
  36. while i<5:
  37. Padrao( "11000000", Delay[1])
  38. Padrao( "01100000", Delay[1])
  39. Padrao( "00110000", Delay[1])
  40. Padrao( "00011000", Delay[1])
  41. Padrao( "00001100", Delay[1])
  42. Padrao( "00000110", Delay[1])
  43. Padrao( "00000011", Delay[1])
  44. Padrao( "10000001", Delay[1])
  45. i=i+1;
  46. i=0;
  47. Padrao( "11000000", Delay[1])
  48. while i<10:
  49. Padrao( "11000000", Delay[1])
  50. Padrao( "01100000", Delay[1])
  51. Padrao( "00110000", Delay[1])
  52. Padrao( "00011000", Delay[1])
  53. Padrao( "00001100", Delay[1])
  54. Padrao( "00000110", Delay[1])
  55. Padrao( "00000011", Delay[1])
  56. Padrao( "00000011", Delay[1])
  57. Padrao( "00000110", Delay[1])
  58. Padrao( "00001100", Delay[1])
  59. Padrao( "00011000", Delay[1])
  60. Padrao( "00110000", Delay[1])
  61. Padrao( "01100000", Delay[1])
  62. Padrao( "11000000", Delay[1])
  63. i=i+1;
  64. i=0;
  65. while i<20:
  66. Padrao( "10000001", Delay[1])
  67. Padrao( "01000010", Delay[1])
  68. Padrao( "00100100", Delay[1])
  69. Padrao( "00011000", Delay[1])
  70. Padrao( "00100100", Delay[1])
  71. Padrao( "01000010", Delay[1])
  72. i=i+1;