Advertisement
Guest User

BeagleBone - Onboard LED KnightRider by Shane B.

a guest
Jan 6th, 2012
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.97 KB | None | 0 0
  1. #Import Libraries
  2. ##################
  3.  
  4. #Tell python we need the library "os" for executing system commands directly
  5. import os
  6.  
  7. #Tell python we need the library "time" so we can use the "sleep" command
  8. import time
  9.  
  10. ##################
  11.  
  12.  
  13. #Define Variables
  14. ##################
  15.  
  16. #Define commands to be executed later on based on logic
  17. #Command for turning led0 "On"
  18. led0_on = 'echo 1 > /sys/class/leds/beaglebone::usr0/brightness'
  19. #Command for turning led0 "Off"
  20. led0_off = 'echo 0 > /sys/class/leds/beaglebone::usr0/brightness'
  21.  
  22.  
  23. #Command for turning led1 "On"
  24. led1_on = 'echo 1 > /sys/class/leds/beaglebone::usr1/brightness'
  25. #Command for turning led1 "Off"
  26. led1_off = 'echo 0 > /sys/class/leds/beaglebone::usr1/brightness'
  27.  
  28. #Command for turning led2 "On"
  29. led2_on = 'echo 1 > /sys/class/leds/beaglebone::usr2/brightness'
  30. #Command for turning led2 "Off"
  31. led2_off = 'echo 0 > /sys/class/leds/beaglebone::usr2/brightness'
  32.  
  33. #Command for turning led3 "On"
  34. led3_on = 'echo 1 > /sys/class/leds/beaglebone::usr3/brightness'
  35. #Command for turning led3 "Off"
  36. led3_off = 'echo 0 > /sys/class/leds/beaglebone::usr3/brightness'
  37. ##################
  38.  
  39.  
  40.  
  41. #Begin Execution
  42. ##################
  43.  
  44. #Infinite On/off loop to make light blink
  45. #Define "i" variable
  46. i = 0;
  47.  
  48. #Begin Infinite loop
  49. while(True):
  50.     if i == 0:
  51.         #Tell Beaglebone that we want LED0 "on"
  52.         os.system(led0_on)
  53.  
  54.         #Tell Beaglebone that we want LED0, LED1 and LED3 "off"
  55.         os.system(led1_off)
  56.         os.system(led2_off)
  57.         os.system(led3_off)
  58.  
  59.         #Tell python to turn led1 on next
  60.         i = 1
  61.  
  62.     elif i == 1:
  63.         #Tell BeagleBone that we want LED1 "on
  64.         os.system(led1_on)
  65.  
  66.         #Tell Beaglebone that we want LED0, LED2 and LED3 "off"
  67.         os.system(led0_off)
  68.         os.system(led2_off)
  69.         os.system(led3_off)
  70.  
  71.         #Tell python to turn led2 on next
  72.         i = 2
  73.  
  74.     elif i == 2:
  75.         #Tell BeagleBone that we want LED2 "on
  76.         os.system(led2_on)
  77.  
  78.         #Tell Beaglebone that we want LED0, LED1 and LED3 "off"
  79.         os.system(led0_off)
  80.         os.system(led1_off)
  81.         os.system(led3_off)
  82.  
  83.         #Tell python to turn led3 on next
  84.         i = 3
  85.  
  86.     elif i == 3:
  87.         #Tell BeagleBone that we want LED3 "on
  88.         os.system(led3_on)
  89.  
  90.         #Tell Beaglebone that we want LED0, LED1 and LED2 "off"
  91.         os.system(led0_off)
  92.         os.system(led1_off)
  93.         os.system(led2_off)
  94.  
  95.         #Tell python to turn led0 on next
  96.         i = 4
  97.  
  98.     elif i == 4:
  99.         #Tell BeagleBone that we want LED2 "on
  100.         os.system(led2_on)
  101.  
  102.         #Tell Beaglebone that we want LED0, LED1 and LED3 "off"
  103.         os.system(led0_off)
  104.         os.system(led1_off)
  105.         os.system(led3_off)
  106.  
  107.         #Tell python to turn led0 on next
  108.         i = 5
  109.  
  110.     elif i == 5:
  111.         #Tell BeagleBone that we want LED1 "on
  112.         os.system(led1_on)
  113.  
  114.         #Tell Beaglebone that we want LED0, LED2 and LED3 "off"
  115.         os.system(led0_off)
  116.         os.system(led2_off)
  117.         os.system(led3_off)
  118.  
  119.         #Tell python to turn led0 on next
  120.         i = 0
  121.  
  122.     #Tell python to pause for 1 second then after the 1 second is over then continue with the infinite while loop
  123.     time.sleep(0.15)
  124.  
  125.  
  126. ##################
  127. #END OF LINE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement