Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * blink12.c:
  3. * Simple sequence over the first 12 GPIO pins - LEDs
  4. * Aimed at the Gertboard, but it's fairly generic.
  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. // Simple sequencer data
  28. // Triplets of LED, On/Off and delay
  29. int data [] =
  30. {
  31. 0, 1, 1,
  32. 1, 1, 1,
  33. 0, 0, 0, 2, 1, 1,
  34. 1, 0, 0, 3, 1, 1,
  35. 2, 0, 0, 4, 1, 1,
  36. 3, 0, 0, 5, 1, 1,
  37. 4, 0, 0, 6, 1, 1,
  38. 5, 0, 0, 7, 1, 1,
  39. 6, 0, 0, 11, 1, 1,
  40. 7, 0, 0, 10, 1, 1,
  41. 11, 0, 0, 13, 1, 1,
  42. 10, 0, 0, 12, 1, 1,
  43. 13, 0, 1,
  44. 12, 0, 1,
  45. 0, 0, 1, // Extra delay
  46. // Back again
  47. 12, 1, 1,
  48. 13, 1, 1,
  49. 12, 0, 0, 10, 1, 1,
  50. 13, 0, 0, 11, 1, 1,
  51. 10, 0, 0, 7, 1, 1,
  52. 11, 0, 0, 6, 1, 1,
  53. 7, 0, 0, 5, 1, 1,
  54. 6, 0, 0, 4, 1, 1,
  55. 5, 0, 0, 3, 1, 1,
  56. 4, 0, 0, 2, 1, 1,
  57. 3, 0, 0, 1, 1, 1,
  58. 2, 0, 0, 0, 1, 1,
  59. 1, 0, 1,
  60. 0, 0, 1,
  61. 0, 0, 1, // Extra delay
  62. 0, 9, 0, // End marker
  63. } ;
  64. int main (void)
  65. {
  66. int pin ;
  67. int dataPtr ;
  68. int l, s, d ;
  69. printf ("Raspberry Pi - 12-LED Sequence\n") ;
  70. printf ("==============================\n") ;
  71. printf ("\n") ;
  72. printf ("Connect LEDs up to the first 8 GPIO pins, then pins 11, 10, 13, 12 in\n") ;
  73. printf (" that order, then sit back and watch the show!\n") ;
  74. wiringPiSetup () ;
  75. for (pin = 0 ; pin < 14 ; ++pin)
  76. pinMode (pin, OUTPUT) ;
  77. dataPtr = 0 ;
  78. for (;;)
  79. {
  80. l = data [dataPtr++] ; // LED
  81. s = data [dataPtr++] ; // State
  82. d = data [dataPtr++] ; // Duration (10ths)
  83. if (s == 9) // 9 -> End Marker
  84. {
  85. dataPtr = 0 ;
  86. continue ;
  87. }
  88. digitalWrite (l, s) ;
  89. delay (d * 100) ;
  90. }
  91. return 0 ;
  92. }