|
@@ -0,0 +1,177 @@
|
|
|
+#include <Eventually.h>
|
|
|
+#include "Adafruit_TLC59711.h"
|
|
|
+#include <SPI.h>
|
|
|
+
|
|
|
+const int BUTTON_PIN[10] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39} ;
|
|
|
+int currentButton ;
|
|
|
+
|
|
|
+//TLC59711
|
|
|
+#define NUM_TLC59711 1
|
|
|
+#define data 28
|
|
|
+#define clock 27
|
|
|
+Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711, clock, data);
|
|
|
+uint32_t ledState[12] ;
|
|
|
+
|
|
|
+//Eventually pointers to manage creation/deletion of listeners
|
|
|
+EvtManager mgr;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool state = LOW;
|
|
|
+int test;
|
|
|
+int test2;
|
|
|
+
|
|
|
+EvtListener *plist;
|
|
|
+EvtListener *plist2;
|
|
|
+
|
|
|
+//Functions prototypes
|
|
|
+void EvtResetButtonContext ();
|
|
|
+void tlcWrite();
|
|
|
+//////////////////////// SETUP /////////////////////////////////
|
|
|
+
|
|
|
+void setup() {
|
|
|
+ Serial.begin(9600);
|
|
|
+
|
|
|
+ tlc.begin();
|
|
|
+ tlc.write();
|
|
|
+// tlc.setLED(0, 65535, 65535, 65535);
|
|
|
+// tlc.setLED(1, 65535, 65535, 65535);
|
|
|
+// tlc.setLED(2, 65535, 65535, 65535);
|
|
|
+// tlc.setLED(3, 65535, 65535, 65535);
|
|
|
+// tlc.write();
|
|
|
+// delay(1000);
|
|
|
+// tlc.setLED(0, 0, 0, 0);
|
|
|
+// tlc.setLED(1, 0, 0, 0);
|
|
|
+// tlc.setLED(2, 0, 0, 0);
|
|
|
+// tlc.setLED(3, 0, 0, 0);
|
|
|
+//// tlcSet(0,65535);
|
|
|
+// tlc.write();
|
|
|
+// delay(500);
|
|
|
+// ledState[3] = 65535 ;
|
|
|
+// tlcWrite();
|
|
|
+// delay(10000);
|
|
|
+ for (int i ; i<12; i++) {
|
|
|
+ Serial.println(i);
|
|
|
+ ledState[i] = 65535 ;
|
|
|
+ tlcWrite();
|
|
|
+ delay (1000);
|
|
|
+ ledState[i] = 0 ;
|
|
|
+ tlcWrite();
|
|
|
+ }
|
|
|
+// }
|
|
|
+// for (int i ; i<12; i++) {
|
|
|
+// Serial.println(i);
|
|
|
+// tlcSet(i, 65535);
|
|
|
+// tlc.write();
|
|
|
+// delay (1000);
|
|
|
+// tlcSet(i,0);
|
|
|
+// tlc.write();
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ //Set button pins as input
|
|
|
+ for (int i ; i < sizeof(BUTTON_PIN)/sizeof(int) ; i++) {
|
|
|
+ pinMode(BUTTON_PIN[i],INPUT_PULLUP) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ EvtResetButtonContext();
|
|
|
+// plist = new EvtTimeListener(1000, true, (EvtAction)blinkme);
|
|
|
+// plist2 = new EvtTimeListener(100, true, (EvtAction)blinkme2);
|
|
|
+// mgr.addListener( plist );
|
|
|
+// //mgr.addListener( plist2 );
|
|
|
+}
|
|
|
+
|
|
|
+///////////////////////////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
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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] = 0 ; }
|
|
|
+ tlcWrite();
|
|
|
+ }
|
|
|
+
|
|
|
+ EvtResetButtonContext() ; //clean context before starting reading the file
|
|
|
+
|
|
|
+ //et après ya plein de trucs à faire
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+bool button0(){
|
|
|
+ buttonFocus(0) ;
|
|
|
+}
|
|
|
+bool button1(){
|
|
|
+ buttonFocus(1) ;
|
|
|
+}
|
|
|
+bool button2(){
|
|
|
+ buttonFocus(2) ;
|
|
|
+}
|
|
|
+bool button3(){
|
|
|
+ buttonFocus(3) ;
|
|
|
+}
|
|
|
+bool button4(){
|
|
|
+ buttonFocus(4) ;
|
|
|
+}
|
|
|
+bool button5(){
|
|
|
+ buttonFocus(5) ;
|
|
|
+}
|
|
|
+bool button6(){
|
|
|
+ buttonFocus(6) ;
|
|
|
+}
|
|
|
+bool button7(){
|
|
|
+ buttonFocus(7) ;
|
|
|
+}
|
|
|
+bool button8(){
|
|
|
+ buttonFocus(8) ;
|
|
|
+}
|
|
|
+bool button9(){
|
|
|
+ buttonFocus(9) ;
|
|
|
+}
|
|
|
+
|
|
|
+void EvtResetButtonContext () {
|
|
|
+ mgr.resetContext();
|
|
|
+ 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));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+///////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+USE_EVENTUALLY_LOOP(mgr) // Use this instead of your loop() function.
|