Stap 9: Firmware versie-Update
De update voegt de functionaliteit van een stopwatch.
Ook, wanneer de timer klaar bent met tellen en piepen, haar begint het tellen van de tijd verstreken sinds het einde van de timer en stopt alleen op de knop drukt.
void initialise() { digitalWrite(MAX7219_CS, HIGH); pinMode(MAX7219_DIN, OUTPUT); pinMode(MAX7219_CS, OUTPUT); pinMode(MAX7219_CLK, OUTPUT); }
void output(byte address, byte data) { digitalWrite(MAX7219_CS, LOW); shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, address); shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, data); digitalWrite(MAX7219_CS, HIGH); }
void setup() { Serial.begin (9600); pinMode (Bot, INPUT); pinMode (BZzz, OUTPUT); // put your setup code here, to run once: initialise(); output(0x0f, 0x00); //display test register - test mode off output(0x0c, 0x01); //shutdown register - normal operation output(0x0b, 0x07); //scan limit register - display digits 0 thru 7 output(0x0a, 0x0f); //intensity register - max brightness output(0x09, 0xff); //decode mode register - CodeB decode all digits output(0x08, 15); //digit 7 (leftmost digit) data output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); //digit 0 (rightmost digit) data
}
void loop() { if (!runMode){ runTime = analogRead (Pot); runTime = map (runTime, 5, 1020, 1, 14) * 5; if (runTime == 70) { runTime = 65; } Serial.println (runTime); if (runTime <= 60) { output(0x05, runTime % 10); output(0x06, runTime / 10); output(0x01, 15); output(0x02, 15); stopWatchMode = false; } if (runTime == stopWatch) { stopWatchMode = true; output(0x01, 0); output(0x02, 0); output(0x05, 0); output(0x06, 0); } if (digitalRead (Bot)) { delay (40); if (!stopWatchMode) { runTime = runTime * 60000 + millis(); tone (BZzz, 300); delay (300); } else { runTime = millis (); tone (BZzz, 200); delay (400); } noTone (BZzz); runMode = true; } if (runMode) { if (!stopWatchMode) { int Bip = true; while (millis() <= runTime) { int minuts, seconds; minuts = (runTime - millis ()) / 60000 ; Serial.print (minuts); output(0x05, minuts % 10); output(0x06, minuts / 10); Serial.print (" : "); seconds = ((runTime - millis ()) % 60000) / 1000; Serial.println (seconds); output(0x01, seconds % 10); output(0x02, seconds / 10); if (digitalRead (Bot)) { while (digitalRead (Bot)) { Bip = false; runMode = false; stopWatchMode = false; //Serial.println ("all False"); output(0x08, 10); //digit 7 (leftmost digit) data output(0x07, 10); output(0x06, 10); output(0x05, 10); output(0x04, 10); output(0x03, 10); output(0x02, 10); output(0x01, 10); } break; } //end if digitalRead Bot } if (Bip) { runTime = millis (); for (int i = 1; i <= 10; i++) { tone (BZzz, 300); output(0x08, 15); //digit 7 (leftmost digit) data output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); delay (200); Serial.println ("Bip Bip Bip..."); noTone (BZzz); output(0x08, 10); //digit 7 (leftmost digit) data output(0x07, 10); output(0x06, 10); output(0x05, 10); output(0x04, 10); output(0x03, 10); output(0x02, 10); output(0x01, 10); delay (200); tone (BZzz, 300); output(0x08, 15); //digit 7 (leftmost digit) data output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); delay (200); Serial.println ("Bip Bip Bip..."); noTone (BZzz); output(0x08, 10); //digit 7 (leftmost digit) data output(0x07, 10); output(0x06, 10); output(0x05, 10); output(0x04, 10); output(0x03, 10); output(0x02, 10); output(0x01, 10); delay (400); stopWatchMode = true; } } // end void Bip output(0x08, 15); //digit 7 (leftmost digit) data output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); //runMode = false; } // end of runMode !stopWatchMode (timer Mode) if (stopWatchMode) { // StopWatch Run Mode begin int minuts, seconds; while (!digitalRead (Bot)) { minuts = (millis () - runTime) / 60000 ; Serial.print (minuts); output(0x05, minuts % 10); output(0x06, minuts / 10); Serial.print (" : "); seconds = ((millis () - runTime) % 60000) / 1000; Serial.println (seconds); output(0x01, seconds % 10); output(0x02, seconds / 10); } runMode = false; stopWatchMode = false; delay (500); } } }
}
void loop {als (! runMode) {runTime = analogRead (Pot); runTime = kaart (runTime, 5, 1020, 1, 14) * 5; als (runTime == 70) {runTime = 65;Serial.println (runTime); Als (runTime < = 60) {output (0x05, runTime 10%); uitvoer (0x06, runTime/10); output(0x01, 15); output(0x02, 15); stopWatchMode = false;Als (runTime == stopWatch) {stopWatchMode = true; output(0x01, 0); output(0x02, 0); output(0x05, 0); output(0x06, 0);Als (digitalRead (Bot)) {vertragen (40); als (! stopWatchMode) {runTime runTime = * 60000 + millis(); Toon (BZzz, 300), vertraging (300);else {runTime = millis (), Toon (BZzz, 200); vertraging (400);noTone (BZzz); runMode = true;Als (runMode) {als (! stopWatchMode) {int Bip = true; terwijl (millis() < = runTime) {int minuten, seconden, minuten = (runTime - millis ()) / 60000; Serial.Print (minuten); output (0x05, 10 minuten %); uitgang (0x06, minuten/10); Serial.Print (":"); seconden = ((runTime - millis ()) % 60000) / 1000; Serial.println (seconden); output (0x01, 10 seconden %); uitgang (0x02, seconden/10); Als (digitalRead (Bot)) {terwijl (digitalRead (Bot)) {Bip = false; runMode = false; stopWatchMode = false; //Serial.println ("alle onwaar"); output(0x08, 10); //digit 7 (meest linkse cijfer) gegevens output(0x07, 10); output(0x06, 10); output(0x05, 10); output(0x04, 10); output(0x03, 10); output(0x02, 10); output(0x01, 10);breken;Als digitalRead BotAls (Bip) {runTime = millis (); voor (int i = 1; ik < = 10; i ++) {Toon (BZzz, 300); output(0x08, 15); //digit 7 (meest linkse cijfer) gegevens output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); vertraging (200); Serial.println ("Bip Bip Bip..."); noTone (BZzz); output(0x08, 10); cijfer 7 (meest linkse cijfer) gegevens output(0x07, 10); output(0x06, 10); output(0x05, 10); output(0x04, 10); output(0x03, 10); output(0x02, 10); output(0x01, 10); vertraging (200); Toon (BZzz, 300); output(0x08, 15); cijfer 7 (meest linkse cijfer) gegevens output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); vertraging (200); Serial.println ("Bip Bip Bip..."); noTone (BZzz); output(0x08, 10); cijfer 7 (meest linkse cijfer) gegevens output(0x07, 10); output(0x06, 10); output(0x05, 10); output(0x04, 10); output(0x03, 10); output(0x02, 10); output(0x01, 10); vertraging (400); stopWatchMode = true;} / / void Bip end output(0x08, 15); cijfer 7 (meest linkse cijfer) gegevens output(0x07, 15); output(0x06, 15); output(0x05, 15); output(0x04, 15); output(0x03, 15); output(0x02, 15); output(0x01, 15); runMode = false;einde van runMode! stopWatchMode (timer Mode) als (stopWatchMode) {/ / StopWatch uitvoermodus beginnen int minuten, seconden, terwijl (! digitalRead (Bot)) {minuten = (millis () - runTime) / 60000; Serial.Print (minuten); output (0x05, 10 minuten %); uitgang (0x06, minuten/10); Serial.Print (":"); seconden = ((millis () - runTime) % 60000) / 1000; Serial.println (seconden); output (0x01, 10 seconden %); uitgang (0x02, seconden/10);runMode = false; stopWatchMode = false; vertraging (500);}