Skip to content

Instantly share code, notes, and snippets.

@zehome zehome/radar.c
Last active Mar 23, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.