/* easy egg timer 2 diget led minute and seconds display line countdown from 99 to -4 need 4 sw reset, up, down, on/start/stop use resistor ladder...you can use any above 15k grnd o----www---www---www---www---o vcc s s s s A2 o---^-----^-----^-----^ 0 256 511 767 aprox reading for A2 D2 o---www---o Vcc 95k - 150k |---www---o A2 20k use Serial.println reading for bank1 window. push stopstart button to wakeup display showes 00 use up, down to set use stop/start like stopwatch 3 sleep modes 1. 00 display and not counting, 1 minute then sleep 2. not counting or no button pushed 3 minute then sleep 3. MAX counting to -5 then sleep use pro mini pulls 30 ma on and .3 ma sleeping -- remove power led 595 row driver top = pin 1 ... bottom = 7 1-7 pins only */ #include Sleep sleep; #define ledWidth 12 // change for # of leds #define SWdelay 250 // sets switch delay + blinks screen #define interval 140 // .139 sec (10 sec fast in 1 hour) // higher interval=slower clock //mmmmmmmmmmmmmmmmmmmmmm pin-outs and numbers mmmmmmmmmmmmm #define clockPinrow 9 // row is single 595 to ground #define dataPinrow 10 #define latchrcPin 11 #define CLOCKPIN 12 #define coldataPin 13 byte x=0; byte Five = 0; byte stopstart=0; //1=countong, 0=stoped byte secline=7; //secline movement byte minline=6; //minute line display int NEXT = 0; //counter goes negitave byte mincount=0; // unsigned int sound=1200; //alarm, starting frequency unsigned long lastcount; //timeout on last switch pressed unsigned long counting; //countdown byte digets[] = { 0,0,57,50, }; //display const byte letter[] = { 193,190,190,190,193, 255,190,128,128,254, 216,182,182,182,206, //0-4 =0 5-9 =1 10-14=2 190,182,182,182,128, 199,247,247,247,128, 134,182,182,182,185, //15-19=3 20-24=4 25-29=5 193,182,182,182,249, 190,189,187,183,143, 201,182,182,182,201, //30-34=6 35-39=7 40-44=8 207,183,182,181,195, 255,255,255,255,255, //45-49=9 50-54=blank 254,253,251,247,239,223,191, //55-61 = secline btm to top 192,224,240,248,252,254, //62-67 minute line top to bottom 255,247,247,247,255, //68-72 - minus }; /////////// functions /////////////////////////// //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm //////// RESET() /////////////////// void RESET() { minline=1; secline=7; lastcount=millis(); noTone(6); } //// end reset() ////////////////////////////////// //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm ////////////////// readSW() function //////////// /// return= leave function --- break= leave case /////// void readSW() { int bank1=1023; bank1 = analogRead(A2); if (bank1>=950) return; //no sw pushed // Serial.begin(9600); // Serial.println(bank1); switch(bank1) { //reset sw --------------------------------------------------- case 750 ... 880: { if(stopstart==1) {return;} tone(6,850,70); delay(SWdelay); RESET(); NEXT=0; break; } //up sw ------------------------------------------------------ case 550 ... 680: { if(stopstart==1) {return;} tone(6,300,70); delay(200); RESET(); NEXT++; if (NEXT==100) NEXT=0; break; } //down sw ---------------------------------------------------- case 300 ... 480: { if(stopstart==1) {return;} tone(6,300,70); delay(200); RESET(); NEXT--; if (NEXT<0) NEXT=99; break; } //stop-start sw --------------- 0 stop -- 1 start counting ----------------------- case 0 ... 30: { tone(6,1200,70); delay(SWdelay); if (NEXT<=0) {stopstart=0; RESET(); NEXT=0; return;} //00 display, stopstart=0 if (stopstart==1) { stopstart=0; lastcount=millis(); break; } //toggle startstop else { stopstart=1; lastcount=millis(); break; } } } //end case bank1 } //end readsw function /// end readsw //////////////////////////////////// //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm /////////////////// sleep function ////////////////////// void gotosleep() { stopstart=0; NEXT=0; RESET(); noTone(6); //turns off speaker PORTB=B00000000; //turns off all B ports 8-13 sleep.pwrDownMode(); //set sleep mode sleep.sleepInterrupt(0,FALLING); //wake reset --------------------------- delay(200); } //////////// end gotosleep ////////////////////////////////////////// //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm void setup() { ///////////////////// runs one time only ///////// pinMode(latchrcPin, OUTPUT); //shared latch row + coll pinMode(CLOCKPIN, OUTPUT); pinMode(coldataPin, OUTPUT); // columns pinMode(clockPinrow, OUTPUT); pinMode(dataPinrow, OUTPUT); // rows pinMode(2,INPUT); //D2 interrupt switch 5v alwaws then sw to 0v pinMode(6,OUTPUT); //D6 alarm speaker } //end setup //^^^^^^^^^^^^^^ END of setup ^^^^^^^^^^^^^^^^ //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm void loop() { readSW(); /////// counting section 60 sec then NEXT-- ////////////////// if (stopstart==0) counting=millis()+interval; if (stopstart==1) { if (millis() >= counting) { counting=millis()+interval; secline++; if (secline==8) { secline=1; mincount++; tone(6,sound,10); } //tone makes 'tick' if (mincount==10) { mincount=0; minline++; } if (minline==7) { NEXT--; mincount=0; minline=1; secline=7; } } } //end stopstart=1 if //sleep conditions ----------------------------------------------------------------- //// stoped or paused or no button pushed for 3 min ... sleep if (stopstart==0 && millis()-lastcount>=180000) { gotosleep(); } //// display 00, 1 min then sleep if (stopstart==0 && NEXT==0 && millis()-lastcount>=60000) { gotosleep(); } //// max countdown -5 then sleep if (stopstart==1 && NEXT== -5) { gotosleep(); } // alarm conditions ----------------------------------------------------------------- if (stopstart==0 && NEXT != 0 && millis()-lastcount>=60000) { tone(6,sound*.9); } //stopped if (stopstart==1 && NEXT <=0) { tone(6,sound++,500); } //countdown if (sound>=1500 && NEXT==0) sound=1200; if (sound>=1600 && NEXT==-1) sound=1300; if (sound>=1700 && NEXT==-2) sound=1400; if (sound>=1800 && NEXT==-3) sound=1500; /// display only section .......... no math, no if, no resets .... /////////// digets display ///////////////////////////////////////////////// if (NEXT== -4) { digets[0]=68; digets[1]=20; } if (NEXT== -3) { digets[0]=68; digets[1]=15; } if (NEXT== -2) { digets[0]=68; digets[1]=10; } if (NEXT== -1) { digets[0]=68; digets[1]=5; } if (NEXT==0) { digets[0]=0; digets[1]=0; } if (NEXT>=1 && NEXT<10) { digets[0]=50; digets[1]=NEXT*5; } if (NEXT>=10 && NEXT<20) { digets[0]=5; digets[1]=(NEXT*5)-50; } if (NEXT>=20 && NEXT<30) { digets[0]=10; digets[1]=(NEXT*5)-100; } if (NEXT>=30 && NEXT<40) { digets[0]=15; digets[1]=(NEXT*5)-150; } if (NEXT>=40 && NEXT<50) { digets[0]=20; digets[1]=(NEXT*5)-200; } if (NEXT>=50 && NEXT<60) { digets[0]=25; digets[1]=(NEXT*5)-250; } if (NEXT>=60 && NEXT<70) { digets[0]=30; digets[1]=(NEXT*5)-300; } if (NEXT>=70 && NEXT<80) { digets[0]=35; digets[1]=(NEXT*5)-350; } if (NEXT>=80 && NEXT<90) { digets[0]=40; digets[1]=(NEXT*5)-400; } if (NEXT>=90) { digets[0]=45; digets[1]=(NEXT*5)-450; } ///// display seconds + minutes collum lines //////////////////////////// if (secline==1) digets[3]=61; if (secline==2) digets[3]=60; if (secline==3) digets[3]=59; if (secline==4) digets[3]=58; if (secline==5) digets[3]=57; if (secline==6) digets[3]=56; if (secline==7) digets[3]=55; if (minline==1) digets[2]=62; //full if (minline==2) digets[2]=63; if (minline==3) digets[2]=64;//half if (minline==4) digets[2]=65; if (minline==5) digets[2]=66;//near bottom if (minline==6) digets[2]=67;//one bottom led /////// end line display /////////////////// ////////////////// LED DISPLAY SCREEN /////////////////// Five=0; x=0; PORTB=B00000000; //latch lo PORTB=B00100000; delayMicroseconds(5); PORTB=B00110000; //one pulse delayMicroseconds(5); PORTB=B00000000; //start one pulse for (byte col=0; col<=ledWidth; col++) { PORTB=B00000000; //latch lo //pushes pulse to end if (col>0) { PORTB=B00010000; delayMicroseconds(5); PORTB=B00000000; } shiftOut(dataPinrow, clockPinrow, LSBFIRST, letter[ digets[x]+(Five++) ] ); PORTB=B00001000; //latch hi if (Five==5) { Five=0; x++; } if (col==9) { x=3; Five=0; } //makes col 9 = digets[3] seconds line if (col==10) { x=2; Five=0; } //makes col 10= digest[2] minute line } //col loop end delay(4); //adj led bright and current draw must reset 'interval' } //loop end THE END END END END