Stap 8: De CODE
#define MAX7219_DIN 5
#define MAX7219_CS 6 #define MAX7219_CLK 7
#define Bot 4 #define BZzz 3 #define Pot 0
boolean runMode = false; long runTime = 0;
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 {als (! runMode) {runTime = analogRead (Pot); runTime = kaart (runTime, 5, 1020, 1, 12) * 5; Serial.println (runTime); output (0x05, runTime 10%); uitgang (0x06, runTime/10); Als (digitalRead (Bot)) {vertraging (20); runTime runTime = * 60000 + millis(); Toon (BZzz, 1000), vertraging (300), noTone (BZzz); runMode = true; void loop() { if (!runMode){ runTime = analogRead (Pot); runTime = map (runTime, 5, 1020, 1, 12) * 5; Serial.println (runTime); output(0x05, runTime % 10); output(0x06, runTime / 10); if (digitalRead (Bot)) { delay (20); runTime = runTime * 60000 + millis(); tone (BZzz, 1000); delay (300); noTone (BZzz); runMode = true; } if (runMode) { 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)) { Bip = false; delay (100); break; } //delay (1000); } if (Bip) { for (int i = 1; i <= 10; i++) { tone (BZzz, 1000); 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, 1000); 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); } } 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; } } Als (runMode) {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)) {Bip = false; vertraging (100); break; } vertraging (1000); #define MAX7219_DIN 5#define MAX7219_CS 6 #define MAX7219_CLK 7 Als (Bip) {voor (int i = 1; ik < = 10; i ++) {Toon (BZzz, 1000); 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, 1000); 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); #define Bot 4 #define BZzz 3 #define Pot 0 } 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; #define stopWatch 65
boolean runMode = false, stopWatchMode; long runTime = 0;