help with arduino programming?
#include <MsTimer2.h>
#define irx 2
static boolean output = HIGH;
int Ledpin = 13;
void setup(){
pinMode(Ledpin, OUTPUT);
pinMode(irx, INPUT);
Serial.begin(9600);
MsTimer2::set(5, flash);
MsTimer2::start();
}
void loop(){
while(digitalRead(irx));
Serial.println("detected");
digitalWrite(Ledpin, HIGH);
}
void flash() {
digitalWrite(12, output);
output = !output;
}
i want the LED to be on when it detects something and go off when it doesnt detect anything, but after it detecs something it stays on for ever... :(
wjhat wrong here?
4
answers
|
Answer it!
|
ok Here is a super simple version, it has been compiled and works great and it only takes up 2406 bytes! (of 30720 bytes max)
int ledPin = 8;
int PirPin = 9;
int val = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(PirPin, INPUT);
}
void loop() {
val = digitalRead(PirPin);
if (val == LOW) {
digitalWrite(ledPin, LOW);
Serial.println("gone");
} else {
digitalWrite(ledPin, HIGH);
Serial.println("detected");
delay(2000); // delay to insure you see the led
}
}
![]() |































