Pages: 1 [2]   Go Down
Author Topic: Serial comm between 2 Arduinos (Now with XBee)  (Read 1892 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  //                            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
« Last Edit: April 15, 2011, 09:57:22 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Red Sea, Saudi Arabia
Offline Offline
God Member
*****
Karma: 12
Posts: 579
..On The Red Sea
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...
PS: If anyone wants me to post my XBee configurations let me know.
Us the Newbies would like to see them, Ayyuuppp!  (VermontSpeak)
Logged

Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Tennessee
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...
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
« Last Edit: April 18, 2011, 08:34:49 am by Grendel » Logged

Tennessee
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, and thank you Mr. Nomad.  I'd actually like to come visit in Australia and stay a few... years   smiley-cool
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: 1 [2]   Go Up
Jump to: