/////////////////////////////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() { //tsunami.update(); updateLeds() ; if (dimmer_random){ dimmer.setTime(50); if (random8(100) > 50) { dimmer.set(percent2PWM(random8(10, 30))); } } else if (dimmer_move) { if (random8(100) > 20) { int timer = millis(); int delta = 2* dimmer_move * (sin8( timer / 9 )-127) * (sin8(timer / 7 )-127) / 65536 ; //- led_move/2 dimmer.setTime(150); dimmer.set(percent2PWM(dimmer_value + delta)); //Serial.println(dimmer_value - delta ); } } FadeLed::update() ; 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) { btnFile.close(); //delay(50); 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] = 10000 ; //65536 max } else { ledState[11-i] = 50 ; } tlcWrite(); } //et après ya plein de trucs à faire String file = "button"; file+=index ; file+=".txt"; btnFile = SD.open(file.c_str(), FILE_READ) ; btnFile.setTimeout(100); //btnFile = SD.open("button0.txt"); Serial.println(""); Serial.println("opening " + file); if (!btnFile) { Serial.println("The text file cannot be opened"); // return false; } // while( EvtResetButtonContext() ; //clean context before starting reading the file //Serial.println("ended buttonReset"); delay_length = 0 ; inibSDreading = false ; //Serial.println("ended focus"); //mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile)); //mgr.addListener(new EvtTimeListener(50, true, (EvtAction)fadeDimmer)); //readSDFile(); } void stopAll() { tsunami.stopAllTracks(); dimmer.setTime(1); dimmer.off(); for (int i ; i