okLed.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * okLed:
  3. * Make the OK LED on the Pi Pulsate...
  4. * Copyright (c) 2012 gordon Henderson, but please Share and Enjoy!
  5. *
  6. * Originally posted to the Raspberry Pi forums:
  7. * http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
  8. *
  9. * Compile this and store it somewhere, then kick it off at boot time
  10. * e.g. by putting it in /etc/rc.local and running it in the
  11. * background &
  12. *
  13. */
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <string.h>
  17. #include <fcntl.h>
  18. #include <unistd.h>
  19. #include <wiringPi.h>
  20. #include <softPwm.h>
  21. #define OK_LED 16
  22. int main ()
  23. {
  24. int fd, i ;
  25. if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
  26. {
  27. fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
  28. return 1 ;
  29. }
  30. write (fd, "none\n", 5) ;
  31. close (fd) ;
  32. if (wiringPiSetupGpio () < 0)
  33. {
  34. fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
  35. return 1 ;
  36. }
  37. softPwmCreate (OK_LED, 0, 100) ;
  38. for (;;)
  39. {
  40. for (i = 0 ; i <= 100 ; ++i)
  41. {
  42. softPwmWrite (OK_LED, i) ;
  43. delay (10) ;
  44. }
  45. delay (50) ;
  46. for (i = 100 ; i >= 0 ; --i)
  47. {
  48. softPwmWrite (OK_LED, i) ;
  49. delay (10) ;
  50. }
  51. delay (10) ;
  52. }
  53. return 0 ;
  54. }