Start arduino part
This commit is contained in:
parent
3741ad1f29
commit
ed24166595
1 changed files with 71 additions and 0 deletions
71
macroboard.ino
Normal file
71
macroboard.ino
Normal 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');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue