Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

126 Zeilen
3.0 KiB

  1. /*
  2. * blink12drcs.c:
  3. * Simple sequence over the first 12 GPIO pins - LEDs
  4. * Aimed at the Gertboard, but it's fairly generic.
  5. * This version uses DRC to talk to the ATmega on the Gertboard
  6. *
  7. * Copyright (c) 2012-2013 Gordon Henderson.
  8. ***********************************************************************
  9. * This file is part of wiringPi:
  10. * https://github.com/WiringPi/WiringPi
  11. *
  12. * wiringPi is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * wiringPi is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  24. ***********************************************************************
  25. */
  26. #include <stdio.h>
  27. #include <wiringPi.h>
  28. #include <drcSerial.h>
  29. #define GERT_BASE 100
  30. static int pinMap [] =
  31. {
  32. 0, 1, 2, 3, // Pi Native
  33. GERT_BASE + 2, GERT_BASE + 3, GERT_BASE + 4, GERT_BASE + 5,
  34. GERT_BASE + 6, GERT_BASE + 7, GERT_BASE + 8, GERT_BASE + 9,
  35. } ;
  36. // Simple sequencer data
  37. // Triplets of LED, On/Off and delay
  38. int data [] =
  39. {
  40. 0, 1, 1,
  41. 1, 1, 1,
  42. 0, 0, 0, 2, 1, 1,
  43. 1, 0, 0, 3, 1, 1,
  44. 2, 0, 0, 4, 1, 1,
  45. 3, 0, 0, 5, 1, 1,
  46. 4, 0, 0, 6, 1, 1,
  47. 5, 0, 0, 7, 1, 1,
  48. 6, 0, 0, 8, 1, 1,
  49. 7, 0, 0, 9, 1, 1,
  50. 8, 0, 0, 10, 1, 1,
  51. 9, 0, 0, 11, 1, 1,
  52. 10, 0, 1,
  53. 11, 0, 1,
  54. 0, 0, 1, // Extra delay
  55. // Back again
  56. 11, 1, 1,
  57. 10, 1, 1,
  58. 11, 0, 0, 9, 1, 1,
  59. 10, 0, 0, 8, 1, 1,
  60. 9, 0, 0, 7, 1, 1,
  61. 8, 0, 0, 6, 1, 1,
  62. 7, 0, 0, 5, 1, 1,
  63. 6, 0, 0, 4, 1, 1,
  64. 5, 0, 0, 3, 1, 1,
  65. 4, 0, 0, 2, 1, 1,
  66. 3, 0, 0, 1, 1, 1,
  67. 2, 0, 0, 0, 1, 1,
  68. 1, 0, 1,
  69. 0, 0, 1,
  70. 0, 0, 1, // Extra delay
  71. 0, 9, 0, // End marker
  72. } ;
  73. int main (void)
  74. {
  75. int pin ;
  76. int dataPtr ;
  77. int l, s, d ;
  78. printf ("Raspberry Pi - 12-LED Sequence\n") ;
  79. printf ("==============================\n") ;
  80. printf ("\n") ;
  81. printf ("Connect LEDs up to the first 4 Pi pins and 8 pins on the ATmega\n") ;
  82. printf (" from PD2 through PB1 in that order,\n") ;
  83. printf (" then sit back and watch the show!\n") ;
  84. wiringPiSetup () ;
  85. drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;
  86. for (pin = 0 ; pin < 12 ; ++pin)
  87. pinMode (pinMap [pin], OUTPUT) ;
  88. dataPtr = 0 ;
  89. for (;;)
  90. {
  91. l = data [dataPtr++] ; // LED
  92. s = data [dataPtr++] ; // State
  93. d = data [dataPtr++] ; // Duration (10ths)
  94. if (s == 9) // 9 -> End Marker
  95. {
  96. dataPtr = 0 ;
  97. continue ;
  98. }
  99. digitalWrite (pinMap [l], s) ;
  100. delay (d * analogRead (GERT_BASE) / 4) ;
  101. }
  102. return 0 ;
  103. }