DownTigerDown.ino 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*TODO
  2. * Fastled and sd reading ?
  3. * stop state
  4. * stop running state
  5. * fade leds
  6. */
  7. #include <Eventually.h>
  8. #include "Adafruit_TLC59711.h"
  9. #include <SD.h>
  10. #include <SPI.h>
  11. #include <Tsunami.h>
  12. #include <FadeLed.h>
  13. //#include <OctoWS2811.h>
  14. #include "FastLED.h"
  15. const int BUTTON_PIN[10] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39} ;
  16. int currentButton ;
  17. // TLC59711
  18. #define NUM_TLC59711 1
  19. #define data 28
  20. #define clock 27
  21. Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711, clock, data);
  22. uint32_t ledState[12] ;
  23. // SD card
  24. File btnFile ;
  25. String buf;
  26. boolean SDfound;
  27. //Tsunami wav player
  28. Tsunami tsunami;
  29. int gNumTracks; // Number of tracks on SD card
  30. char gTsunamiVersion[VERSION_STRING_LEN]; // Tsunami version string
  31. //Eventually pointers to manage creation/deletion of listeners
  32. EvtManager mgr;
  33. EvtListener *pSD; // identified listener for non-blocking file reading
  34. EvtListener *pDelay ;
  35. //delay
  36. int delay_start ;
  37. unsigned long delay_length ;
  38. bool inibSDreading = true;
  39. bool delay_flag ; //prevent first event to fire
  40. //Dimmer
  41. #define DIMMER_PIN 9
  42. FadeLed dimmer(DIMMER_PIN);
  43. // FastLED
  44. #define NUM_LEDS_LUSTRE 240
  45. CRGB lustreLeds[NUM_LEDS_LUSTRE];
  46. byte lustre_currentBrightness ; //for fading
  47. byte lustre_targetBrightness ;
  48. int lustre_stepBrightness;
  49. CRGBPalette16 lustre_currentPalette( CRGB::Blue);
  50. CRGBPalette16 lustre_targetPalette( CRGB::Red );
  51. #define NUM_LEDS_TABLE 50
  52. CRGB tableLeds[NUM_LEDS_TABLE];
  53. byte table_currentBrightness ;
  54. byte table_targetBrightness ;
  55. int table_stepBrightness;
  56. CRGBPalette16 table_currentPalette( CRGB::Pink);
  57. CRGBPalette16 table_targetPalette( CRGB::Blue );
  58. // FastLED Palettes
  59. CRGBPalette16 TIGER_DOWN_MER (CRGB::DarkBlue);
  60. CRGBPalette16 SOLEIL (CRGB::Orange);
  61. CRGBPalette16 CREPUSCULE (CRGB::YellowGreen);
  62. CRGBPalette16 FLAMINGO (CRGB::LightCoral);
  63. //Functions prototypes
  64. void EvtResetButtonContext ();
  65. void tlcWrite();
  66. void buttonFocus(int);
  67. //////////////////////// SETUP /////////////////////////////////
  68. void setup() {
  69. Serial.begin(9600);
  70. // TLC
  71. tlc.begin();
  72. tlc.write();
  73. // SD
  74. Serial.println("Lecture carte SD");
  75. if (SDfound == 0) {
  76. if (!SD.begin(BUILTIN_SDCARD)) {
  77. Serial.print("The SD card cannot be found");
  78. while(1);
  79. }
  80. }
  81. SDfound = 1;
  82. // DIMMER
  83. dimmer.off();
  84. // LEDS
  85. FastLED.addLeds<NEOPIXEL, 2>(lustreLeds, NUM_LEDS_LUSTRE);
  86. FastLED.addLeds<NEOPIXEL, 14>(tableLeds, NUM_LEDS_TABLE);
  87. // TSUNAMI
  88. // We should wait for the Tsunami to finish reset
  89. Serial.println("Demarrage du Tsunami wav player");
  90. delay(1000);
  91. tsunami.start();
  92. delay(10);
  93. tsunami.stopAllTracks();
  94. tsunami.samplerateOffset(0, 0);
  95. tsunami.setReporting(true);
  96. delay(100);
  97. if (tsunami.getVersion(gTsunamiVersion, VERSION_STRING_LEN)) {
  98. Serial.print(gTsunamiVersion);
  99. Serial.print("\n");
  100. gNumTracks = tsunami.getNumTracks();
  101. Serial.print("Number of tracks = ");
  102. Serial.print(gNumTracks);
  103. Serial.print("\n");
  104. }
  105. else
  106. Serial.print("WAV Trigger response not available");
  107. tsunami.setReporting(false);
  108. //Set button pins as input
  109. for (int i ; i < sizeof(BUTTON_PIN)/sizeof(int) ; i++) {
  110. pinMode(BUTTON_PIN[i],INPUT_PULLUP) ;
  111. }
  112. //EvtResetButtonContext();
  113. Serial.println();
  114. Serial.println();
  115. Serial.println("Demarrage termine, activation etat 0");
  116. // btnFile = SD.open("button0.txt");
  117. // while(!btnFile.available()){
  118. // Serial.println("bah alors");
  119. // }
  120. delay (3000) ;
  121. buttonFocus(0) ;
  122. // EvtResetButtonContext ();
  123. }
  124. ///////////////////////////// LOOP //////////////////////////////////
  125. USE_EVENTUALLY_LOOP(mgr) // Use this instead of your loop() function.
  126. //void loop() {
  127. // mgr.loopIteration();
  128. // //updateAll();
  129. //}