Thursday, May 6, 2010

Infrared Send/Recieve (Task 45)

I set this up to run on a single arduino board (pin 13 being an input and 12 being output) but the code can easily be adapted so that one board can act as a sender and another as a receiver.

int infra;
int count = 0;

void setup(){
pinMode(13,INPUT);
pinMode(12,OUTPUT);
Serial.begin(9600);
}

void loop(){
for (int i = 0; i < 21; i ++){
digitalWrite(12,HIGH);
infra = digitalRead(13);
delay(500);

if (infra == HIGH){
count = count + 1;
Serial.println(count);
}
else{
Serial.print(count);
Serial.println(" Blocked");
digitalWrite(12,LOW);
}
}
Serial.println("Finished");
delay(1000);
}

No comments:

Post a Comment