Advertisement
Guest User

Binary on LEDs

a guest
Jul 16th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #!/bin/bash
  2. # Raspberry Pi and wiringpi
  3. # Display byte as binary on leds connected to GPIO
  4. # RPi GPIO
  5. # MSB to LSB
  6. # BCM    25 24 23 22 10 09 08 07
  7. # HEADER 22 18 16 15 23 21 24 26
  8. #
  9. # gpio init
  10. gpio=gpio
  11. for P in 22 18 16 15 23 21 24 26; do
  12.   $gpio mode $P out
  13. done
  14. echo -n "$1 to binary "
  15. #MSB to LSB
  16. if [ $(($1 & 128)) -eq 128 ]; then
  17.   echo -n 1
  18.   $gpio write 22 1
  19. else
  20.   echo -n 0
  21.   $gpio write 22 0
  22. fi
  23. if [ $(($1 & 64)) -eq 64 ]; then
  24.   echo -n 1
  25.   $gpio write 18 1
  26. else
  27.   echo -n 0
  28.   $gpio write 18 0
  29. fi
  30. if [ $(($1 & 32)) -eq 32 ]; then
  31.   echo -n 1
  32.   $gpio write 16 1
  33. else
  34.   echo -n 0
  35.   $gpio write 16 0
  36. fi
  37. if [ $(($1 & 16)) -eq 16 ]; then
  38.   echo -n 1
  39.   $gpio write 15 1
  40. else
  41.   echo -n 0
  42.   $gpio write 15 0
  43. fi
  44. if [ $(($1 & 8)) -eq 8 ]; then
  45.   echo -n 1
  46.   $gpio write 23 1
  47. else
  48.   echo -n 0
  49.   $gpio write 23 0
  50. fi
  51. if [ $(($1 & 4)) -eq 4 ]; then
  52.   echo -n 1
  53.   $gpio write 21 1
  54. else
  55.   echo -n 0
  56.   $gpio write 21 0
  57. fi
  58. if [ $(($1 & 2)) -eq 2 ]; then
  59.   echo -n 1
  60.   $gpio write 24 1
  61. else
  62.   echo -n 0
  63.   $gpio write 24 0
  64. fi
  65. if [ $(($1 & 1)) -eq 1 ]; then
  66.   echo -n 1
  67.   $gpio write 26 1
  68. else
  69.   echo -n 0
  70.   $gpio write 26 0
  71. fi
  72. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement