|
@@ -156,407 +156,13 @@ void setup() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-///////////////////////// TEST ALL DEVICES /////////////////////////////
|
|
|
|
|
|
-void testAll(){
|
|
|
-
|
|
|
- mgr.resetContext();
|
|
|
- // TLC
|
|
|
- Serial.println("Test boutons");
|
|
|
- for (int i ; i<12; i++) {
|
|
|
-
|
|
|
- ledState[i] = 65535 ;
|
|
|
- tlcWrite();
|
|
|
- delay (100);
|
|
|
- ledState[i] = 0 ;
|
|
|
- tlcWrite();
|
|
|
-
|
|
|
- }
|
|
|
- for (int i ; i < sizeof(ledState)/sizeof(uint32_t) ; i++) {
|
|
|
-
|
|
|
- if (i == 1 ) {
|
|
|
- ledState[11-i] = 65535 ;
|
|
|
- }
|
|
|
- else { ledState[11-i] = 50 ; }
|
|
|
- tlcWrite();
|
|
|
- }
|
|
|
-
|
|
|
- // DIMMER
|
|
|
- Serial.println("Test dimmer");
|
|
|
- dimmer.off();
|
|
|
- while (!dimmer.done()) {FadeLed::update();}
|
|
|
- //delay(2000);
|
|
|
- Serial.println("fading up");
|
|
|
- dimmer.setTime(2000);
|
|
|
- dimmer.on();
|
|
|
- while (!dimmer.done()) {FadeLed::update();}
|
|
|
- Serial.println("fading down");
|
|
|
- dimmer.off();
|
|
|
- while (!dimmer.done()) {FadeLed::update();}
|
|
|
-
|
|
|
-// FastLED
|
|
|
- Serial.println("Test leds");
|
|
|
- for (int i ; i<NUM_LEDS_LUSTRE ; i++) {
|
|
|
- lustreLeds[i] = CRGB::White ;
|
|
|
- tableLeds[i] = CRGB::White ;
|
|
|
- FastLED.show();
|
|
|
-// delay(1);
|
|
|
-// lustreLeds[i] = CRGB::Black ;
|
|
|
-// tableLeds[i] = CRGB::Black ;
|
|
|
-// FastLED.show();
|
|
|
- }
|
|
|
-
|
|
|
- // AUDIO
|
|
|
- Serial.println("Test son");
|
|
|
- tsunami.trackPlayPoly(101, 0, true);
|
|
|
- //delay(500);
|
|
|
- //tsunami.update();
|
|
|
- tsunami.trackPlayPoly(102, 0, true);
|
|
|
- //delay(500);
|
|
|
- //tsunami.update();
|
|
|
- tsunami.trackPlayPoly(103, 1, true);
|
|
|
- //delay(500);
|
|
|
- //tsunami.update();
|
|
|
- tsunami.trackPlayPoly(104, 1, true);
|
|
|
- //delay(500);
|
|
|
- //tsunami.update();
|
|
|
- tsunami.trackPlayPoly(105, 2, true);
|
|
|
- //delay(500);
|
|
|
- //tsunami.update();
|
|
|
- tsunami.trackPlayPoly(106, 2, true);
|
|
|
- //delay(500);
|
|
|
- // tsunami.update();
|
|
|
- tsunami.trackPlayPoly(107, 3, true);
|
|
|
- //delay(500);
|
|
|
- //tsunami.update();
|
|
|
- tsunami.trackPlayPoly(108, 3, true);
|
|
|
- //tsunami.update();
|
|
|
- //delay(500);
|
|
|
-
|
|
|
- Serial.println("fin du test");
|
|
|
- EvtResetButtonContext();
|
|
|
-// stopAll();
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-///////////////////////// FastLED ///////////////////////////////////////
|
|
|
-
|
|
|
-
|
|
|
-void FillLEDsFromPaletteColors( CRGB leds[], int NUM_LED, CRGBPalette16 palette, uint8_t colorIndex){
|
|
|
- uint8_t brightness = 255;
|
|
|
- for( int i = 0; i < NUM_LED; i++) {
|
|
|
- leds[i] = ColorFromPalette( palette, colorIndex + sin8(i*16), 255);
|
|
|
- colorIndex += 3;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-byte FadingBrightness (int FastLEDindex, byte currentBrightness, byte targetBrightness, int step) {
|
|
|
- if (currentBrightness != targetBrightness) { currentBrightness += step ;}
|
|
|
- else Serial.println("fade done");
|
|
|
- FastLED[FastLEDindex].showLeds(currentBrightness) ;
|
|
|
- return currentBrightness ;
|
|
|
-}
|
|
|
-
|
|
|
-void updateLeds(){
|
|
|
- nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
|
|
|
- FillLEDsFromPaletteColors(lustreLeds,NUM_LEDS_LUSTRE, lustre_currentPalette, 0);
|
|
|
-// uint8_t secondHand = (millis() / 10) ;
|
|
|
- lustre_currentBrightness = FadingBrightness( 0, lustre_currentBrightness ,255,1);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-///////////////////////// SD ////////////////////////////////////////////
|
|
|
-
|
|
|
-String getSubstring(String dataString, char separator, int index)
|
|
|
-{
|
|
|
- int found = 0;
|
|
|
- int strIndex[] = { 0, -1 };
|
|
|
- int maxIndex = dataString.length() - 1;
|
|
|
-
|
|
|
- for (int i = 0; i <= maxIndex && found <= index; i++) {
|
|
|
- if (dataString.charAt(i) == separator || i == maxIndex) {
|
|
|
- found++;
|
|
|
- strIndex[0] = strIndex[1] + 1;
|
|
|
- strIndex[1] = (i == maxIndex) ? i+1 : i;
|
|
|
- }
|
|
|
- }
|
|
|
- return found > index ? dataString.substring(strIndex[0], strIndex[1]) : "";
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool readSDFile() {
|
|
|
-
|
|
|
- if (!inibSDreading) { // if currently delaying, don't read a line
|
|
|
- if (btnFile.available()) {
|
|
|
- buf = btnFile.readStringUntil('\n');
|
|
|
-
|
|
|
- //check selector (1st word of line) and execute corresponding function
|
|
|
- String selector = getSubstring(buf, ' ', 0);
|
|
|
- //Serial.println(selector);
|
|
|
-
|
|
|
- if (selector == "sound") {
|
|
|
- String track = getSubstring(buf, ' ', 2) ;
|
|
|
- String out = getSubstring(buf, ' ', 1) ;
|
|
|
- Serial.println("Playing track " + track + " to output " + out);
|
|
|
- tsunami.trackPlayPoly(track.toInt(), out.toInt()-1, true);
|
|
|
- }
|
|
|
-
|
|
|
- else if (selector == "led") {
|
|
|
-// String mode = getSubstring(buf, ' ', 1);
|
|
|
-// if (mode == "L"){
|
|
|
-// int R = getSubstring(buf, ' ', 2).toInt();
|
|
|
-// int G = getSubstring(buf, ' ', 3).toInt();
|
|
|
-// int B = getSubstring(buf, ' ', 4).toInt();
|
|
|
-// for (int i ; i<NUM_LEDS_LUSTRE ; i++) {
|
|
|
-// lustreLeds[i].setRGB(R, G, B) ;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (mode == "T"){
|
|
|
-// int R = getSubstring(buf, ' ', 2).toInt();
|
|
|
-// int G = getSubstring(buf, ' ', 3).toInt();
|
|
|
-// int B = getSubstring(buf, ' ', 4).toInt();
|
|
|
-// for (int i ; i<NUM_LEDS_TABLE ; i++) {
|
|
|
-// tableLeds[i].setRGB(R, G, B) ;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// Serial.println("Led mode " + getSubstring(buf, ' ', 1));
|
|
|
- }
|
|
|
-
|
|
|
- else if (selector == "dimmer") {
|
|
|
- Serial.println("Dimmer fade à " + getSubstring(buf, ' ', 1) + " en " + getSubstring(buf, ' ', 2) + "ms");
|
|
|
- int dimmer_value = getSubstring(buf, ' ', 1).toInt();
|
|
|
- int dimmer_fade = getSubstring(buf, ' ', 2).toInt();
|
|
|
- dimmer.setTime(dimmer_fade);
|
|
|
- dimmer.set(dimmer_value);
|
|
|
- // Serial.println(dimmer_delta);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- else if (selector == "delay") {
|
|
|
- String wait = getSubstring(buf, ' ', 1);
|
|
|
- Serial.println("delai " + wait + " ms");
|
|
|
- inibSDreading = true ;
|
|
|
- delay_start = millis();
|
|
|
- delay_length = wait.toInt() ;
|
|
|
-// delay_flag = 0 ;
|
|
|
- mgr.addListener(new EvtTimeListener(50 , true, (EvtAction)checkDelay));
|
|
|
-
|
|
|
- //delay(wait.toInt());
|
|
|
- }
|
|
|
-
|
|
|
- else if (selector == ""){}
|
|
|
-
|
|
|
- else {
|
|
|
- Serial.print(selector);
|
|
|
- Serial.println(": pas compris");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- else {
|
|
|
- Serial.println("EOF");
|
|
|
-
|
|
|
- btnFile.close();
|
|
|
- inibSDreading = true;
|
|
|
- EvtResetButtonContext();
|
|
|
- }
|
|
|
- }
|
|
|
-// else{Serial.println("not reading");}
|
|
|
- return false ;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-/////////////////////////////Events/////////////////////////////////
|
|
|
-///*resetButtonContext create a listener for each button
|
|
|
-// * when triggered, thoses listener execute the same functions with the index of the pressed button :
|
|
|
-// * resetButtonContext and kill any running sequence
|
|
|
-// * buttonFocus -> lights the current button and shuts the others
|
|
|
-// * readSequence -> reads a text file on the SD card with the sequence of actions to execute
|
|
|
-// */
|
|
|
-
|
|
|
-bool checkDelay() {
|
|
|
- //Serial.println("checkDelay");
|
|
|
- //if (delay_flag == 0 ) { delay_flag = 1 ;}
|
|
|
- if (millis() - delay_start > delay_length ) {
|
|
|
- inibSDreading = false ;
|
|
|
- }
|
|
|
- //else {inibSDreading = false ;}
|
|
|
- return false ;
|
|
|
-}
|
|
|
-
|
|
|
-bool updateAll() {
|
|
|
+///////////////////////////// LOOP //////////////////////////////////
|
|
|
|
|
|
- FadeLed::update();
|
|
|
- //tsunami.update();
|
|
|
- updateLeds() ;
|
|
|
-// FastLED.show();
|
|
|
- return false;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void tlcWrite(){
|
|
|
- for (int ledIndex ; ledIndex < 12 ; ledIndex++) { //sizeof(ledState)/sizeof(uint32_t)
|
|
|
-
|
|
|
- int indexDiv = ledIndex / 3 ;
|
|
|
-
|
|
|
- tlc.setLED(indexDiv, ledState[indexDiv*3], ledState[indexDiv*3+1], ledState[indexDiv*3+2]);
|
|
|
-// Serial.print(ledState[ledIndex]);
|
|
|
-// Serial.print(" ");
|
|
|
- }
|
|
|
-// Serial.println();
|
|
|
- tlc.write();
|
|
|
-}
|
|
|
-
|
|
|
-void buttonFocus(int index) {
|
|
|
- currentButton = index ;
|
|
|
- //Serial.println(currentButton);
|
|
|
- //turn off all leds but currentButton one
|
|
|
- for (int i ; i < sizeof(ledState)/sizeof(uint32_t) ; i++) {
|
|
|
-
|
|
|
- if (i == currentButton ) {
|
|
|
- ledState[11-i] = 65535 ;
|
|
|
- }
|
|
|
- else { ledState[11-i] = 50 ; }
|
|
|
- tlcWrite();
|
|
|
- }
|
|
|
-
|
|
|
- EvtResetButtonContext() ; //clean context before starting reading the file
|
|
|
-
|
|
|
- //et après ya plein de trucs à faire
|
|
|
- String file = "button";
|
|
|
- file+=index ;
|
|
|
- file+=".txt";
|
|
|
- btnFile = SD.open(file.c_str()) ;
|
|
|
-// btnFile = SD.open("button0.txt");
|
|
|
- Serial.println("opening " + file);
|
|
|
- if (!btnFile) {
|
|
|
- Serial.println("The text file cannot be opened");
|
|
|
-// return false;
|
|
|
- }
|
|
|
-// while(
|
|
|
- inibSDreading = false ;
|
|
|
- //mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
|
|
|
- //mgr.addListener(new EvtTimeListener(50, true, (EvtAction)fadeDimmer));
|
|
|
- //readSDFile();
|
|
|
+USE_EVENTUALLY_LOOP(mgr) // Use this instead of your loop() function.
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-void stopAll() {
|
|
|
- tsunami.stopAllTracks();
|
|
|
- dimmer.setTime(1);
|
|
|
- dimmer.off();
|
|
|
- for (int i ; i<NUM_LEDS_LUSTRE ; i++) {
|
|
|
- lustreLeds[i] = CRGB::Black ;
|
|
|
- tableLeds[i] = CRGB::Black ;
|
|
|
- }
|
|
|
- FastLED.show();
|
|
|
- for (int i ; i < sizeof(ledState)/sizeof(uint32_t) ; i++) {
|
|
|
-
|
|
|
- if (i == 4 ) {
|
|
|
- ledState[11-i] = 65535 ;
|
|
|
- }
|
|
|
- else { ledState[11-i] = 50 ; }
|
|
|
- tlcWrite();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- EvtResetButtonContext();
|
|
|
-}
|
|
|
-
|
|
|
-///////////////////// CONTEXT ///////////////////////////////
|
|
|
-
|
|
|
-bool button0(){
|
|
|
- buttonFocus(0) ;
|
|
|
- lustre_targetPalette = FLAMINGO ;
|
|
|
- lustre_currentBrightness = 0;
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button1(){
|
|
|
- buttonFocus(1) ;
|
|
|
- lustre_targetPalette = SOLEIL;
|
|
|
- lustre_currentBrightness = 0;
|
|
|
-// testAll();
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button2(){
|
|
|
- buttonFocus(2) ;
|
|
|
- lustre_targetPalette = CREPUSCULE ;
|
|
|
- lustre_currentBrightness = 0;
|
|
|
-
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button3(){
|
|
|
- buttonFocus(3) ;
|
|
|
- lustre_targetPalette =TIGER_DOWN_MER;
|
|
|
- lustre_currentBrightness = 0;
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button4(){
|
|
|
- buttonFocus(4) ;
|
|
|
-// stopAll();
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button5(){
|
|
|
- buttonFocus(5) ;
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button6(){
|
|
|
- buttonFocus(6) ;
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button7(){
|
|
|
- buttonFocus(7) ;
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button8(){
|
|
|
- buttonFocus(8) ;
|
|
|
- return false;
|
|
|
-}
|
|
|
-bool button9(){
|
|
|
- buttonFocus(9) ;
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
-void EvtResetButtonContext () {
|
|
|
- Serial.println("Resetting event context");
|
|
|
- mgr.resetContext();
|
|
|
- // button listeners
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[0], (EvtAction)button0));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[1], (EvtAction)button1));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[2], (EvtAction)button2));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[3], (EvtAction)button3));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[4], (EvtAction)button4));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[5], (EvtAction)button5));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[6], (EvtAction)button6));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[7], (EvtAction)button7));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[8], (EvtAction)button8));
|
|
|
- mgr.addListener(new EvtPinListener(BUTTON_PIN[9], (EvtAction)button9));
|
|
|
-
|
|
|
- // controlled time listeners
|
|
|
-// pSD = new EvtTimeListener(5, true, (EvtAction)readSDFile);
|
|
|
- inibSDreading = true ;
|
|
|
- mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
|
|
|
- mgr.addListener(new EvtTimeListener(25, true, (EvtAction)updateAll));
|
|
|
- //mgr.addListener(new EvtTimeListener(40, true, (EvtAction)fastLeds));
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-///////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
-//USE_EVENTUALLY_LOOP(mgr) // Use this instead of your loop() function.
|
|
|
-
|
|
|
-void loop() {
|
|
|
- mgr.loopIteration();
|
|
|
- //updateAll();
|
|
|
-}
|
|
|
+//void loop() {
|
|
|
+// mgr.loopIteration();
|
|
|
+// //updateAll();
|
|
|
+//}
|
|
|
|