//This program increases a counter displayed on a 7-segment display by 1. This program is an up counter. Changing line 47 to decrement will turn the code into a down counter. //The library used in this code is different from the library used in the final code. However, the functions functioanlities remain the same. Only the syntax is changed. #include //{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; //0~9,A,b,C,d,E,F #define CLK 26//Pins for TM1637 #define DIO 27 #define BUTTON 40 int count = 0, count_1, count_2, count_3, count_4, count_5, count_6, count_7; int control= 0; TM1637 tm1637(CLK,DIO); void setup(){ tm1637.init(); tm1637.set(2); //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; pinMode(BUTTON,INPUT); tm1637.display(3,1); tm1637.display(2,2); tm1637.display(1,3); tm1637.display(0,4); delay(1500);//Delay to let system boot }//end "setup()" void loop(){ if(digitalRead(BUTTON) == HIGH) { control = HIGH; } while(digitalRead(BUTTON) == HIGH) { } if(digitalRead(BUTTON) == LOW and control == HIGH) { count++; control = LOW; } if(count == 999) { count = 0; } count_1 = count%10; count_3 = (count/10)%10; count_5 = (count/100)%10; count_7 = (count/1000)%10; tm1637.display(3,count_1); tm1637.display(2,count_3); tm1637.display(1,count_5); tm1637.display(0,count_7); delay(10); }// end loop()