Thursday, April 29, 2010

Task 48 - receiving and sending a copy back for checking.

I was working with BJ on this. On my arduino I had the following code:

int reciever = 2;
int LED = 13;

void setup(){
pinMode(reciever,INPUT);
Serial.begin(9600);
}

void loop(){
//val = digitalRead(reciever);
if (digitalRead(reciever)==1){
Serial.println("H");
digitalWrite(LED,HIGH);
}
else{
digitalWrite(LED,LOW);
Serial.println("L");
}
delay(500);
}

on BJ's arduino, he had the following code:

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
pinMode(2,INPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
if(digitalRead(2)==1){
Serial.println('H');
}
else{
Serial.println('L');
}
digitalWrite(ledPin, LOW);
delay(1000);
if(digitalRead(2)==1){
Serial.println('H');
}
else{
Serial.println('L');
}
}

When blink goes on BJ's arduino it sends a signal to my arduino that outputs high or low to the screen, depending if it is a one or two. It then sends it back to BJ's arduino and does the same thing and outputs high or low to the screen.

No comments:

Post a Comment