RGB LED



/*
 * three-phase current 
 * connect the anodes of an RGB-LED with Pins 9,10,11
 * tools --> serial plotter (IDE 1.6.7 or higher)
 */

void setup() {
  Serial.begin(9600);
  Serial.println(F(__FILE__));
}

float t;

void loop() {
  float r = sin(t);
  float g = sin(t + 2 * PI / 3);
  float b = sin(t + 4 * PI / 3);
  pwm( 9, r);
  pwm(10, g);
  pwm(11, b);
  Serial.println(0); // = r + g + b
  delay(10);
  t = t + 0.01;
}

byte pwm(byte pin, float val) {
  analogWrite(pin, (1 + val) * 127);
  Serial.print(4 * val);
  Serial.print(' ');
}



contact: nji(at)gmx.de