Last active
March 23, 2019 20:03
-
-
Save zehome/9c83b40276e0fd778ce143df4815cc2c to your computer and use it in GitHub Desktop.
leslie radar using arduino
This file contains 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
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