Commit 4c39241e authored by Nicolas Lenz's avatar Nicolas Lenz
Browse files

Add readout sketch

parent b3dd7fd5
/*
For testing purposes:
This just reads out the states of all keys every 0,5 seconds and prints them
to the serial interface.
*/
const byte keyPins[] = {2,3,4,5,6,7,8,9}; // the pin numbers for the keys in the keys' order
const byte keyNum = 8;
void setup() {
Serial.begin(9600);
// initialize the pins
for(int i = 0; i < keyNum; i++) {
pinMode(keyPins[i], INPUT_PULLUP);
}
}
bool readKey(byte key) {
// when the key is pressed, digitalRead returns 0, so we have to negate the output.
return !digitalRead(keyPins[key]);
}
void loop() {
for(int i = 0; i < keyNum; i++) {
Serial.println("Key " + String(i) + ": " + (readKey(i) ? "pressed" : "not pressed"));
}
Serial.println();
delay(500);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment