Guide

www.SquishyCircuits.com Page 10
Code:
//Squishy RGB LED Controller
//Port Definitions and Variable Declarations:
#define RED_LED 9
#define GREEN_LED 10
#define BLUE_LED 11
int analog_RED = 0; // common resistor connected to analog pin 0 outside leads to ground and +5V
int raw_RED = 0; // variable to store the raw input value
int BRIGHTNESS_RED = 0; //Variable to store Brightness Value (0-255)
int analog_GREEN = 1; // common resistor connected to analog pin 1 // outside leads to ground and +5V
int raw_GREEN = 0; // variable to store the raw input value
int BRIGHTNESS_GREEN = 0; //Variable to store Brightness Value (0-255)
int analog_BLUE = 2; // common resistor connected to analog pin 2 // outside leads to ground and +5V
int raw_BLUE = 0; // variable to store the raw input value
int BRIGHTNESS_BLUE = 0; //Variable to store Brightness Value (0-255)
void setup()
{
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(BLUE_LED, OUTPUT);
}
void loop()
{
//Read Voltages over Dough:
raw_RED = analogRead(analog_RED);
raw_GREEN = analogRead(analog_GREEN);
raw_BLUE = analogRead(analog_BLUE);
//Generate Brightness Value (PWM Values = 0-255) from Raw Voltages (0- 1023)
if(raw_RED <=150) {BRIGHTNESS_RED=255;}
if(raw_RED >=500) {BRIGHTNESS_RED=0;}
else {BRIGHTNESS_RED=-.7286*raw_RED+364.45;}
analogWrite(RED_LED, BRIGHTNESS_RED); //Output PWM Value to Light
if(raw_GREEN <=150) {BRIGHTNESS_GREEN=255;}
if(raw_GREEN >=500) {BRIGHTNESS_GREEN=0;}
else {BRIGHTNESS_GREEN=-.7286*raw_GREEN+364.45;}
analogWrite(GREEN_LED, BRIGHTNESS_GREEN); //Output PWM Value to Light
if(raw_BLUE <=150) {BRIGHTNESS_BLUE=255;}
if(raw_BLUE >=500) {BRIGHTNESS_BLUE=0;}
else {BRIGHTNESS_BLUE=-.7286*raw_BLUE+364.45;}
analogWrite(BLUE_LED, BRIGHTNESS_BLUE); //Output PWM Value to Light
}