Add paddle sketch for Arduino
This commit is contained in:
parent
ad7ba0ce02
commit
8783d4f43e
1 changed files with 27 additions and 0 deletions
27
paddle/paddle.ino
Normal file
27
paddle/paddle.ino
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const int dot_pin = 2;
|
||||
const int dash_pin = 3;
|
||||
|
||||
char last_state = 'X';
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(dot_pin, INPUT_PULLUP);
|
||||
pinMode(dash_pin, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
char current_state = '0';
|
||||
if (digitalRead(dot_pin) == LOW) {
|
||||
current_state += 1;
|
||||
}
|
||||
if (digitalRead(dash_pin) == LOW) {
|
||||
current_state += 2;
|
||||
}
|
||||
|
||||
if (current_state != last_state) {
|
||||
Serial.print(current_state);
|
||||
last_state = current_state;
|
||||
}
|
||||
delay(1); // Limit update rate under 1kHz
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue