Christy Spielman
Published © GPL3+

Light mixer with output RGB values

Arduino code that mixes the RGB light on a Digital Sandbox and outputs the values to the serial monitor.

EasyWork in progress129
Light mixer with output RGB values

Things used in this project

Hardware components

SparkFun Digital Sandbox
SparkFun Digital Sandbox
×1

Code

Light mixing

Arduino
Arduino code for use with Digital Sandbox to test light mixing with output values for RGB.
int red;  
int green;
int blue;
int fade_red;
int fade_green;
int fade_blue;
int fade_up;
int fade_down;
// Anything defined in the space _above_ setup() is GLOBAL. 
// A global // variable can be used in both the setup() and loop() functions. 
// We'll want to use fade in both of those functions.

void setup()
{
  Serial.begin(9600);
  Serial.println("Color Mixing!");

  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT);  
  pinMode(11, OUTPUT);  
  
  red = 0;  
  green = 60;
  blue = 120;
  fade_red = 5;
  fade_green = 5;
  fade_blue = 5;
  fade_up = 5;
  fade_down = -5;
}

void loop()
{
  if (digitalRead(12) == HIGH)
  {
  }
  else 
  {
    analogWrite(9, red);
    analogWrite(10, green);
    analogWrite(11, blue);
    red = red + fade_red; // Increment fade by 1
    green = green + fade_green; // Increment fade by 1
    blue = blue + fade_blue;  // Increment fade by 1
    Serial.print(red);
    Serial.print(", ");
    Serial.print(green);
    Serial.print(", ");
    Serial.print(blue);
    Serial.println();
    if (red > 180)
      fade_red = fade_down;
    if (green > 180)
      fade_green = fade_down;
    if (blue > 180)
      fade_blue = fade_down;
    if (red < 10)
      fade_red = fade_up;
    if (green < 10)
      fade_green = fade_up;
    if (blue < 10)
      fade_blue = fade_up;
    delay(100); // Wait half a second
  }
}

Credits

Christy Spielman

Christy Spielman

1 project • 0 followers

Comments