Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const int sensorPin = 9; // PW socket on sensor board
const int relayPin = 10; //
const int threshold = 48; //
const bool DEBUG = false;
int ticks = 0;
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
}
void loop() {
long distance = pulseIn(sensorPin, HIGH) / 147;
Serial.println(distance);
if (distance < threshold && distance != 0) {
ticks++;
if (ticks > 2) {
ticks = 0;
if (DEBUG) {
Serial.println("Trigger");
Serial.println(distance);
Serial.println("--------------------------");
} else {
digitalWrite(relayPin, HIGH);
Keyboard.write(49);
}
delay(10 * 1000);
}
}
else {
digitalWrite(relayPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.