2019-11-23 09:29:23 +00:00
|
|
|
/// ----------------------------------------------------------------
|
|
|
|
/// ----------------------- 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
|
2019-11-23 22:31:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2019-11-23 09:29:23 +00:00
|
|
|
if (current_state == WaitingForInput) {
|
|
|
|
for (byte i = 0; i < pin_count; i++) {
|
|
|
|
check_pin(pins[i], i);
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 22:31:21 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// debug
|
|
|
|
Serial.println("test");
|
|
|
|
|
2019-11-24 07:37:26 +00:00
|
|
|
delay(2000);
|
2019-11-23 09:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|