Last active
January 31, 2018 10:09
-
-
Save hhayley/f870a297f04e264f2d09e35eb03d528b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Based on Example/09.USB/KeyboardAndMouseControl example code by Tom Igoe | |
modified by Hayeon Hwang | |
- MKR1000 | |
- water level sensor -> A0 | |
- push button -> D4 | |
*/ | |
#include "Keyboard.h" | |
int upButton = 4; | |
int watersensor = A0; | |
int waterlevel = 0; | |
void setup() { | |
pinMode(upButton, INPUT); | |
pinMode(watersensor, INPUT); | |
Serial.begin(9600); | |
Keyboard.begin(); | |
} | |
void loop() { | |
waterlevel = analogRead(watersensor); | |
// Serial.println(waterlevel); | |
// use the pushbuttons to control the keyboard: | |
if (digitalRead(upButton) == HIGH) { | |
Keyboard.press(KEY_UP_ARROW); | |
} else if (digitalRead(upButton) != HIGH) { | |
Keyboard.release(KEY_UP_ARROW); | |
} | |
if (waterlevel <= 50) { | |
//right | |
Keyboard.press(KEY_RIGHT_ARROW); | |
Keyboard.release(KEY_LEFT_ARROW); | |
delay(50); | |
} else if (waterlevel < 200) { | |
//middle | |
Keyboard.release(KEY_LEFT_ARROW); | |
Keyboard.release(KEY_RIGHT_ARROW); | |
} else { | |
//left | |
Keyboard.press(KEY_LEFT_ARROW); | |
Keyboard.release(KEY_RIGHT_ARROW); | |
delay(50); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment