Skip to content

Instantly share code, notes, and snippets.

@hhayley
Last active January 31, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhayley/f870a297f04e264f2d09e35eb03d528b to your computer and use it in GitHub Desktop.
Save hhayley/f870a297f04e264f2d09e35eb03d528b to your computer and use it in GitHub Desktop.
/*
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