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.
 
 
 
 
 

116 righe
2.9 KiB

  1. /*
  2. * blink6drcs.c:
  3. * Simple sequence over 6 pins on a remote DRC board.
  4. * Aimed at the Gertduino, but it's fairly generic.
  5. * This version uses DRC to talk to the ATmega on the Gertduino
  6. *
  7. * Copyright (c) 2012-2014 Gordon Henderson. <projects@drogon.net>
  8. ***********************************************************************
  9. * This file is part of wiringPi:
  10. * https://projects.drogon.net/raspberry-pi/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. GERT_BASE + 6, GERT_BASE + 5, GERT_BASE + 3, GERT_BASE + 10, GERT_BASE + 9, GERT_BASE + 13,
  33. } ;
  34. // Simple sequencer data
  35. // Triplets of LED, On/Off and delay
  36. int data [] =
  37. {
  38. 0, 1, 1,
  39. 1, 1, 1,
  40. 0, 0, 0, 2, 1, 1,
  41. 1, 0, 0, 3, 1, 1,
  42. 2, 0, 0, 4, 1, 1,
  43. 3, 0, 0, 5, 1, 1,
  44. 4, 0, 1,
  45. 5, 0, 1,
  46. 0, 0, 1, // Extra delay
  47. // Back again
  48. 5, 1, 1,
  49. 4, 1, 1,
  50. 5, 0, 0, 3, 1, 1,
  51. 4, 0, 0, 2, 1, 1,
  52. 3, 0, 0, 1, 1, 1,
  53. 2, 0, 0, 0, 1, 1,
  54. 1, 0, 1,
  55. 0, 0, 1,
  56. 0, 0, 1, // Extra delay
  57. 0, 9, 0, // End marker
  58. } ;
  59. int main (void)
  60. {
  61. int pin ;
  62. int dataPtr ;
  63. int l, s, d ;
  64. printf ("Raspberry Pi - 6-LED Sequence\n") ;
  65. printf ("=============================\n") ;
  66. printf ("\n") ;
  67. printf (" Use the 2 buttons to temporarily speed up the sequence\n") ;
  68. wiringPiSetupSys () ; // Not using the Pi's GPIO here
  69. drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;
  70. for (pin = 0 ; pin < 6 ; ++pin)
  71. pinMode (pinMap [pin], OUTPUT) ;
  72. pinMode (GERT_BASE + 16, INPUT) ; // Buttons
  73. pinMode (GERT_BASE + 17, INPUT) ;
  74. pullUpDnControl (GERT_BASE + 16, PUD_UP) ;
  75. pullUpDnControl (GERT_BASE + 17, PUD_UP) ;
  76. dataPtr = 0 ;
  77. for (;;)
  78. {
  79. l = data [dataPtr++] ; // LED
  80. s = data [dataPtr++] ; // State
  81. d = data [dataPtr++] ; // Duration (10ths)
  82. if (s == 9) // 9 -> End Marker
  83. {
  84. dataPtr = 0 ;
  85. continue ;
  86. }
  87. digitalWrite (pinMap [l], s) ;
  88. delay (d * digitalRead (GERT_BASE + 16) * 15 + digitalRead (GERT_BASE + 17) * 20) ;
  89. }
  90. return 0 ;
  91. }