/* This uses a lot of code from the sample code from the TM1638 example. */ #include int i = 0; unsigned long a=0; byte buttons; unsigned long timermax=0; // set by buttons //unsigned long timer=0; //counter for timer countdown byte isset = 0; // define a module on data pin 8, clock pin 9 and strobe pin 7 TM1638 module(8, 9, 7); void setup() { Serial.begin(9600); // wait for the TM1638 to finish intializing. delay(500); // reset our counter a = 0; // Set up the display and turn down brightness. module.setupDisplay(true,2); } void loop() { //We will just count and increment/deincrement the LED bar for show. //LEDs from 0 to 8 in red. for(i=0; i<8; i++) { a=a+1; module.setDisplayToDecNumber(a,0,true); module.setLED(TM1638_COLOR_RED, i); delay(250); } //LEDs from 8 to 0 in green. for(i=7; i>=0; i--) { a=a+1; module.setDisplayToDecNumber(a,0,true); module.setLED(TM1638_COLOR_GREEN, i); delay(250); } //Read buttons, start "Game mode" buttons=module.getButtons(); if(buttons != 0) { module.setDisplayToString("SEt ",0,0); switch (buttons){ case 1: timermax=1200; //20 minutes break; case 2: timermax=600; // 10 minutes break; case 4: timermax=300; // 5 minutes break; case 8: timermax=60; // 1 minute break; case 16: timermax=10; // 10sec break; default: timermax=1200; } module.setDisplayToDecNumber(timermax,0,false); module.setDisplayToString("SEt ",0,0); delay(1000); for(long timer = timermax; timer>=1; timer--) { Serial.print(timer,DEC); module.setDisplayToDecNumber(timer,1,false); module.setDisplayToString("run ",0,0); delay(1000); if( isset==0) { module.setLEDs(0x00FF); isset=1; } else { module.setLEDs(0xFF00); isset=0; } } // When for loop ends, we do something awesome module.setDisplayToString("--SHOTS--",0,0); for(i=32; i>=0; i--) { module.setLEDs(0x00FF); delay(125); module.setLEDs(0xFF00); delay(125); } } }