54 lines
1,000 B
C++
54 lines
1,000 B
C++
|
|
#define RED_LED 6
|
|
#define GREEN_LED 9
|
|
#define BLUE_LED 5
|
|
|
|
int brightness = 255;
|
|
int rb = 0;
|
|
int gb = 0;
|
|
int bb = 0;
|
|
int fadeSpeed = 10;
|
|
|
|
void setup()
|
|
{
|
|
pinMode(RED_LED, OUTPUT);
|
|
pinMode(GREEN_LED, OUTPUT);
|
|
pinMode(BLUE_LED, OUTPUT);
|
|
|
|
Serial.begin(115200);
|
|
}
|
|
|
|
char* result[3];
|
|
|
|
void loop()
|
|
{
|
|
if(Serial.available() > 1)
|
|
{
|
|
char input[12];
|
|
byte size = Serial.readBytes(input, 11);
|
|
// Add the final 0 to end the C string
|
|
input[size] = 0;
|
|
|
|
// Read each command pair
|
|
char* command = strtok(input, ";");
|
|
int index = 0;
|
|
while (command != 0)
|
|
{
|
|
result[index] = command;
|
|
index += 1;
|
|
// Find the next command in input string
|
|
command = strtok(0, ";");
|
|
}
|
|
|
|
rb = atoi(result[0]);
|
|
gb = atoi(result[1]);
|
|
bb = atoi(result[2]);
|
|
|
|
analogWrite(RED_LED, rb);
|
|
analogWrite(GREEN_LED, gb);
|
|
analogWrite(BLUE_LED, bb);
|
|
|
|
//String out = (String)rb + ";" + (String)gb + ";" + (String)bb;
|
|
//Serial.println(out);
|
|
}
|
|
}
|