Skip to content

Instantly share code, notes, and snippets.

@zehome
Last active March 23, 2019 20:03
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 zehome/9c83b40276e0fd778ce143df4815cc2c to your computer and use it in GitHub Desktop.
Save zehome/9c83b40276e0fd778ce143df4815cc2c to your computer and use it in GitHub Desktop.
leslie radar using arduino
const int pwPin = 7;
const int led = 11;
void setup()
{
Serial.begin(115200);
pinMode(pwPin, INPUT);
pinMode(led, OUTPUT);
}
void loop() {
long pulses;
long cm;
static int latch = 0;
static long nextlatch = 0;
pulses = pulseIn(pwPin, HIGH);
//cm = (pulses / 147.2) * 2.54;
//Serial.print(cm);
//Serial.print("cm");
//Serial.println();
long now = millis();
if (pulses < 3500 && pulses > 300) {
if (nextlatch < now) {
latch = 1;
}
nextlatch = now + (10*1000);
} else {
latch = 0;
}
Serial.print("latch: "); Serial.print(latch);
Serial.print(" now: "); Serial.print(now);
Serial.print(" nextlatch: "); Serial.print(nextlatch);
Serial.print(" pulses: ");
Serial.print(pulses);
Serial.println();
if (latch == 1) {
analogWrite(led,250);
delay(100);
analogWrite(led,0);
delay(50);
analogWrite(led,250);
delay(50);
analogWrite(led,0);
latch = 0;
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment