No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

67 líneas
1.2 KiB

  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 <math.h>
  20. #include <wiringPi.h>
  21. #include <softPwm.h>
  22. #define OK_LED 16
  23. int main ()
  24. {
  25. int fd, i ;
  26. if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
  27. {
  28. fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
  29. return 1 ;
  30. }
  31. write (fd, "none\n", 5) ;
  32. close (fd) ;
  33. if (wiringPiSetupGpio () < 0)
  34. {
  35. fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
  36. return 1 ;
  37. }
  38. softPwmCreate (OK_LED, 0, 100) ;
  39. for (;;)
  40. {
  41. for (i = 0 ; i <= 100 ; ++i)
  42. {
  43. softPwmWrite (OK_LED, i) ;
  44. delay (10) ;
  45. }
  46. delay (50) ;
  47. for (i = 100 ; i >= 0 ; --i)
  48. {
  49. softPwmWrite (OK_LED, i) ;
  50. delay (10) ;
  51. }
  52. delay (10) ;
  53. }
  54. return 0 ;
  55. }