Go Down

Topic: Serial comm between 2 Arduinos (Now with XBee) (Read 3328 times) previous topic - next topic

Graynomad

#15
Apr 15, 2011, 04:55 pm Last Edit: Apr 15, 2011, 04:57 pm by Graynomad Reason: 1
There are always a 100 ways to write code for a given problem, but here's one example that I think will do the same job.

Code: [Select]
  //                            RGB       RGB       RGB       RGB
  byte bit_patterns [] = {B00000000,B00000010,B00000100,B00000001};


void loop()
{
if(mySerial.available() > 0)
{
char val = mySerial.read();   
char b = bit_patterns[val - '0']; // note, no bounds checking, we could get a 'Z'

Serial.print("recieved:");
Serial.println(val); //Print what Arduino 1 is sending

digitalWrite(blueLed, b & 1);
b >>= 1;
digitalWrite(greenLed, b & 1);
b >>= 1;
digitalWrite(redLed, b & 1);
}
}


_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

TerryKing


...
PS: If anyone wants me to post my XBee configurations let me know.

Us the Newbies would like to see them, Ayyuuppp!  (VermontSpeak)

Grendel

#17
Apr 18, 2011, 03:32 pm Last Edit: Apr 18, 2011, 03:34 pm by Grendel Reason: 1


...
PS: If anyone wants me to post my XBee configurations let me know.

Us the Newbies would like to see them, Ayyuuppp!  (VermontSpeak)

Ask and ye shall receive...




I guess I should clarify that I am using the XBee Series 2 radios

Grendel

Oh, and thank you Mr. Nomad.  I'd actually like to come visit in Australia and stay a few... years   8)

Graynomad

Quote
I'd actually like to come visit in Australia and stay a few... years

You're most welcome, the country is about the same size as the 'States but with the population of NY so we've got plenty of room :).

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up