Start arduino part

This commit is contained in:
hodasemi 2019-11-23 10:29:23 +01:00
parent 3741ad1f29
commit ed24166595

71
macroboard.ino Normal file
View file

@ -0,0 +1,71 @@
/// ----------------------------------------------------------------
/// ----------------------- Type Definitions -----------------------
/// ----------------------------------------------------------------
enum State {
WaitingForInput,
WaitingForAck,
};
/// ----------------------------------------------------------------
/// ----------------------- Board Specifics ------------------------
/// ----------------------------------------------------------------
const int pin_count = 8;
const byte pins[pin_count] = {
2, 3, 4, 5, 6, 7, 8, 9
};
const char message_start = '<';
const char message_end = '>';
/// ----------------------------------------------------------------
/// -------------------------- Variables ---------------------------
/// ----------------------------------------------------------------
State current_state;
/// ----------------------------------------------------------------
/// --------------------------- Startup ----------------------------
/// ----------------------------------------------------------------
void setup() {
// enable serial port, with 9600 Baud
Serial.begin(9600);
// setup variables
current_state = WaitingForInput;
// setup pins
for (byte i = 0; i < pin_count; i++) {
pinMode(pins[i], INPUT);
}
}
void loop() {
// check for possible input
if (current_state == WaitingForInput) {
for (byte i = 0; i < pin_count; i++) {
check_pin(pins[i], i);
}
}
}
void check_pin(byte pin, byte index) {
if (digitalRead(pin) == HIGH) {
// assemble message
Serial.print(message_start);
Serial.print(index + 1);
Serial.print(message_end);
// force new line
Serial.print('\n');
}
}