25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blink.c 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * blink.c:
  3. * Standard "blink" program in wiringPi. Blinks an LED connected
  4. * to the first GPIO pin.
  5. *
  6. * Copyright (c) 2012-2013 Gordon Henderson.
  7. ***********************************************************************
  8. * This file is part of wiringPi:
  9. * https://github.com/WiringPi/WiringPi
  10. *
  11. * wiringPi is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * wiringPi is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  23. ***********************************************************************
  24. */
  25. #include <stdio.h>
  26. #include <wiringPi.h>
  27. #include <signal.h>
  28. // LED Pin - wiringPi
  29. // pin 0 is BCM_GPIO 17
  30. // pin 1 is BCM_GPIO 18
  31. // pin 2 is BCM_GPIO 27
  32. #define LED 2
  33. static int terminate_process = 0;
  34. static void Signal_handler(int sig);
  35. int main (void)
  36. {
  37. printf ("Raspberry Pi blink\n") ;
  38. if (wiringPiSetup () == -1)
  39. return 1 ;
  40. pinMode (LED, OUTPUT) ;
  41. // Set the handler for SIGTERM (15)
  42. signal(SIGTERM, Signal_handler);
  43. signal(SIGHUP, Signal_handler);
  44. signal(SIGINT, Signal_handler);
  45. signal(SIGQUIT, Signal_handler);
  46. signal(SIGTRAP, Signal_handler);
  47. signal(SIGABRT, Signal_handler);
  48. signal(SIGALRM, Signal_handler);
  49. signal(SIGUSR1, Signal_handler);
  50. signal(SIGUSR2, Signal_handler);
  51. while (!terminate_process)
  52. {
  53. digitalWrite (LED, HIGH) ; // On
  54. delay (500) ; // mS
  55. digitalWrite (LED, LOW) ; // Off
  56. delay (500) ;
  57. }
  58. digitalWrite (LED, LOW) ; // Off
  59. return 0 ;
  60. }
  61. //**********************************************************************************************************************
  62. /**
  63. * Intercepts and handles signals from QNX
  64. * This function is called when the SIGTERM signal is raised by QNX
  65. */
  66. void Signal_handler(int sig)
  67. {
  68. printf("Received signal %d\n", sig);
  69. // Signal process to exit.
  70. terminate_process = 1;
  71. }
  72. //**********************************************************************************************************************