DownTigerDown.ino 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. const int audioVolumePin = A21 ;
  32. int audioMasterVolume = 0 ;
  33. //Eventually pointers to manage creation/deletion of listeners
  34. EvtManager mgr;
  35. EvtListener *pSD; // identified listener for non-blocking file reading
  36. EvtListener *pDelay ;
  37. //delay
  38. int delay_start ;
  39. unsigned long delay_length ;
  40. bool inibSDreading = true;
  41. bool delay_flag ; //prevent first event to fire
  42. byte refreshRate = 23 ;
  43. //Dimmer
  44. #define DIMMER_PIN 9
  45. FadeLed dimmer(DIMMER_PIN);
  46. int dimmer_value = 15;
  47. byte dimmer_low = 20;
  48. byte dimmer_mid = 60;
  49. byte dimmer_high = 80;
  50. bool dimmer_random = false; // activate short-circuit effect
  51. int dimmer_move = 7;
  52. // FastLED
  53. #define NUM_LEDS_LUSTRE 140
  54. CRGB lustreLeds[NUM_LEDS_LUSTRE];
  55. float lustre_currentBrightness = 0; //for fading
  56. float lustre_targetBrightness = 0 ;
  57. float lustre_stepBrightness = 0;
  58. CRGBPalette16 lustre_currentPalette( CRGB::Green);
  59. CRGBPalette16 lustre_targetPalette( CRGB::Orange );
  60. #define NUM_LEDS_TABLE 20
  61. CRGB tableLeds[NUM_LEDS_TABLE];
  62. float table_currentBrightness ;
  63. float table_targetBrightness ;
  64. float table_stepBrightness;
  65. CRGBPalette16 table_currentPalette( CRGB::Pink);
  66. CRGBPalette16 table_targetPalette( CRGB::Blue );
  67. // FastLED Palettes
  68. CRGBPalette16 palette_MER (CRGB::DarkBlue);
  69. CRGBPalette16 palette_SOLEIL (CRGB::Orange);;
  70. CRGBPalette16 palette_CREPUSCULE (CRGB::Blue);
  71. CRGBPalette16 palette_FLAMINGO (CRGB::LightCoral);
  72. bool palette_BEAT = false; // activate beat sync palette
  73. int paletteBeatStart ; //to resync effect on activation
  74. int BPM =120;
  75. bool palette_MOVE = true ;
  76. int led_move = 80 ; // organic variation around base value
  77. //Functions prototypes
  78. void EvtResetButtonContext ();
  79. void tlcWrite();
  80. void buttonFocus(int);
  81. //////////////////////// SETUP /////////////////////////////////
  82. void setup() {
  83. Serial.begin(9600);
  84. // TLC
  85. tlc.begin();
  86. tlc.write();
  87. // SD
  88. Serial.println("Lecture carte SD");
  89. if (SDfound == 0) {
  90. if (!SD.begin(BUILTIN_SDCARD)) {
  91. Serial.print("The SD card cannot be found");
  92. while(1);
  93. }
  94. }
  95. SDfound = 1;
  96. readSDconfig();
  97. // DIMMER
  98. dimmer.off();
  99. // dimmer.set(percent2PWM(25));
  100. // dimmer.setTime(0, true);
  101. // while(!dimmer.done()){FadeLed::update();}
  102. // delay(2000);
  103. // dimmer.setTime(5000, true);
  104. // dimmer.set(percent2PWM(2));
  105. // while(!dimmer.done()){FadeLed::update();}
  106. //
  107. // LEDS
  108. FastLED.addLeds<NEOPIXEL, 2>(lustreLeds, NUM_LEDS_LUSTRE);
  109. FastLED.addLeds<NEOPIXEL, 14>(tableLeds, NUM_LEDS_TABLE);
  110. // TSUNAMI
  111. // We should wait for the Tsunami to finish reset
  112. Serial.println("Demarrage du Tsunami wav player");
  113. delay(1000);
  114. tsunami.start();
  115. delay(10);
  116. tsunami.stopAllTracks();
  117. tsunami.samplerateOffset(0, 0);
  118. tsunami.setReporting(true);
  119. delay(100);
  120. if (tsunami.getVersion(gTsunamiVersion, VERSION_STRING_LEN)) {
  121. Serial.print(gTsunamiVersion);
  122. Serial.print("\n");
  123. gNumTracks = tsunami.getNumTracks();
  124. Serial.print("Number of tracks = ");
  125. Serial.print(gNumTracks);
  126. Serial.print("\n");
  127. }
  128. else
  129. Serial.print("WAV Trigger response not available");
  130. tsunami.setReporting(false);
  131. //Set button pins as input
  132. for (int i ; i < sizeof(BUTTON_PIN)/sizeof(int) ; i++) {
  133. pinMode(BUTTON_PIN[i],INPUT_PULLUP) ;
  134. }
  135. //EvtResetButtonContext();
  136. Serial.println();
  137. Serial.println();
  138. Serial.println("Demarrage termine, activation etat 0");
  139. // btnFile = SD.open("button0.txt");
  140. // while(!btnFile.available()){
  141. // Serial.println("bah alors");
  142. // }
  143. delay (3000) ;
  144. EvtResetButtonContext ();
  145. buttonFocus(0) ;
  146. }
  147. ///////////////////////////// LOOP //////////////////////////////////
  148. USE_EVENTUALLY_LOOP(mgr) // Use this instead of your loop() function.