Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions demos/rgb/sketch/sketch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
int color[3];
int index;
int colorIndex;

void setup() {
while (!Serial) {
Expand All @@ -17,13 +17,13 @@ void setup() {
Serial.begin(9600);
Serial.write("Sketch begins.\r\n");
Serial.flush();
index = 0;
colorIndex = 0;
}

void loop() {
if (Serial && Serial.available()) {
color[index++] = Serial.read();
if (index == 3) {
color[colorIndex++] = Serial.read();
if (colorIndex == 3) {
analogWrite(redPin, color[0]);
analogWrite(greenPin, color[1]);
analogWrite(bluePin, color[2]);
Expand All @@ -35,7 +35,7 @@ void loop() {
Serial.print(color[2]);
Serial.print(".\r\n");
Serial.flush();
index = 0;
colorIndex = 0;
}
}
}
}