summaryrefslogtreecommitdiff
path: root/Arduino sketch/serial_rgb.pde
blob: f6121a2af35550c71a35bd1ce874bfefac3411b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#define LEDR      9
#define LEDG     10
#define LEDB     11

int r, g, b;

void setup()
{
  pinMode(LEDR, OUTPUT);
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
  r = g = b = 0;
  
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available() >= 3)
  {
    r = Serial.read();
    g = Serial.read();
    b = Serial.read();
    Serial.write('1'); // Sync
  }
  analogWrite(LEDR, r);
  analogWrite(LEDG, g);
  analogWrite(LEDB, b);
}