Stap 2: Code...
#define MAX7219_DIN 5
#define MAX7219_CS 6 #define MAX7219_CLK 7
#define leftB 8 #define rightB 9 #define RESETb 10
int left, right, rightPlay, leftPlay = 0; boolean changeIndc = false; int SRead;
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 (leftB, INPUT); pinMode (rightB, INPUT); // 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, 0x00); //digit 7 (leftmost digit) data output(0x07, 0x0a); output(0x06, 0x00); output(0x05, 0x00); output(0x04, 0x00); output(0x03, 0x00); output(0x02, 0x0a); output(0x01, 0x00); //digit 0 (rightmost digit) data
}
void loop {SRead = Serial.read (); als (SRead == 48 || digitalRead (RESETb)) {Serial.println ("RESET"), links = 0; rechts = 0; leftPlay = 0; rightPlay = 0; changeIndc = true; output (0x01, 0); output (0x08, 0); void loop() { SRead = Serial.read (); if (SRead ==48 || digitalRead (RESETb)) { Serial.println ("RESET"); left = 0; right = 0; leftPlay = 0; rightPlay = 0; changeIndc = true; output (0x01, 0); output (0x08, 0); } if (SRead == 49 || digitalRead (leftB)) { delay (200); while (digitalRead (leftB)) {} left++; changeIndc = true; } if (SRead == 50 || digitalRead (rightB)) { delay (200); while (digitalRead (rightB)) {} right++; changeIndc = true; } if (changeIndc) { output(0x03, left % 10); output(0x04, left / 10); output(0x05, right % 10); output(0x06, right / 10); if (right >=11 && right >= left +2) { rightPlay ++; right = 0; left = 0; output (0x08, rightPlay); } if (left >=11 && left >= right + 2) { leftPlay ++; right = 0; left = 0; output (0x01, leftPlay); } changeIndc = false; } Als (SRead == 49 || digitalRead (LINKSB)) {vertragen (200); terwijl (digitalRead (LINKSB)) {} links ++; changeIndc = true; } Als (SRead == 50 || digitalRead (RECHTSB)) {vertragen (200); terwijl (digitalRead (RECHTSB)) {} recht ++; changeIndc = true;Als (changeIndc) {output (0x03, linker 10%); uitvoer (0x04, links/10); output (0x05, toch 10%); uitvoer (0x06, juiste/10); als (juiste > = 11 & en rechts > links + 2 =) {rightPlay ++; rechts = 0 links = 0; uitgang (0x08, rightPlay);Als (links > = 11 & & links > = recht + 2) {leftPlay ++; rechts = 0 links = 0; uitgang (0x01, leftPlay);changeIndc = false;