Hello,
I have problems reading an ASCII String with my Arduino Micro.
When I upload the code from the Tutorial (http://arduino.cc/en/Tutorial/ReadASCIIString), I can control the LED's by entering something like "10,250,10" in the serial monitor.
But I want to control one Arcuino Micro by another.
So, for testing I set up the Transmitter-Arduino with following code:
void setup()
{
Serial1.begin(9600);
}
void loop()
{
Serial1.println("1,250,1");
delay(500);
Serial1.println("250,1,250");
delay(500);
}
And I modified the code from the Tutorial to receive serial data from the RX pin (replaced every "serial" with "serial1"):
// pins for the LEDs:
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
void setup() {
// initialize serial:
Serial1.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// if there's any serial available, read it:
while (Serial1.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial1.parseInt();
// do it again:
int green = Serial1.parseInt();
// do it again:
int blue = Serial1.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial1.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
red = constrain(red, 0, 255);
green = constrain(green, 0, 255);
blue = constrain(blue, 0, 255);
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
But nothing is happening. I don't know where the mistake is and I'm trying to find out since days now.
I'm grateful for every help.
Thanks
Flo