/* From Arduino Examples
Reading a serial ASCII-encoded string.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
Circuit: Common-Cathode RGB LED wired like so:
- red anode: digital pin 3 through 220 ohm resistor
- green anode: digital pin 5 through 220 ohm resistor
- blue anode: digital pin 6 through 220 ohm resistor
- cathode: GND
created 13 Apr 2012
by Tom Igoe
modified 14 Mar 2016
by Arturo Guadalupi
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadASCIIString
*/
// pins for the LEDs:
const int LED1Pin = 2;
//const int LED2Pin = 3;
//const int LED3Pin = 4;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(LED1Pin, OUTPUT);
// pinMode(LED2Pin, OUTPUT);
//pinMode(LED2Pin, OUTPUT);
Serial.println("Enter number 1 or 0 to turn LED on off");
}
void loop() {
// if there's any serial available, read it:
if (Serial.available() > 0) {
int LED1 = Serial.parseInt();
//int LED2 = Serial.parseInt();
// look for the newline. That's the end of your sentence:
//if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
// print the three numbers in one string as hexadecimal:
Serial.println(LED1);
//Serial.print(", ");
//Serial.println(LED2);
//Serial.print(", ");
//}
}
}