Skip to content

Instantly share code, notes, and snippets.

@dwaq
Last active December 16, 2015 17:29
Show Gist options
  • Save dwaq/5470767 to your computer and use it in GitHub Desktop.
Save dwaq/5470767 to your computer and use it in GitHub Desktop.
//*************************************************************************************************
// Adjustable RGB LED Color Cube
//
// By: Dillon Nichols
// http://tinkeringetc.blogspot.com/2013/07/adjustable-rgb-led-color-cube.html
//
// Created in Arduino 1.0.5
//
// Description:
// Drives four strips of RGB LEDs inside a cube structure by the use of a controller that
// selects the strip and the color of the strip.
//
// This work is licensed under a Creative Commons Attribution 3.0 Unported License.
//*************************************************************************************************
// Map pins for the color-adjustment potentiometers
int redPot = 2;
int greenPot = 1;
int bluePot = 0;
// Map pins for the LEDs
int redLED1 = 13;
int greenLED1 = 12;
int blueLED1 = 11;
int redLED2 = 10;
int greenLED2 = 9;
int blueLED2 = 8;
int redLED3 = 7;
int greenLED3 = 6;
int blueLED3 = 5;
int redLED4 = 4;
int greenLED4 = 3;
int blueLED4 = 2;
// Create variables to store the brightness of each primary color
int redVal = 0;
int greenVal = 0;
int blueVal = 0;
// Create variables to set which side of the cube will be adjustable
int oneON = 0;
int twoON = 0;
int threeON = 0;
int fourON = 0;
void setup() {
// Set up all of the LED pins as outputs
pinMode(redLED1, OUTPUT);
pinMode(greenLED1, OUTPUT);
pinMode(blueLED1, OUTPUT);
pinMode(redLED2, OUTPUT);
pinMode(greenLED2, OUTPUT);
pinMode(blueLED2, OUTPUT);
pinMode(redLED3, OUTPUT);
pinMode(greenLED3, OUTPUT);
pinMode(blueLED3, OUTPUT);
pinMode(redLED4, OUTPUT);
pinMode(greenLED4, OUTPUT);
pinMode(blueLED4, OUTPUT);
// Set up interrupts for the four buttons
attachInterrupt(5, one, FALLING);
attachInterrupt(3, two, FALLING);
attachInterrupt(2, three, FALLING);
attachInterrupt(4, four, FALLING);
}
void loop() {
// Read the analog potentiometer value and scale from 0-1023 to 0-255
redVal = analogRead(redPot) / 4;
greenVal = analogRead(greenPot) / 4;
blueVal = analogRead(bluePot) / 4;
// Change the side chosen by the button interupt to the color from the potentiometers
if (oneON == 1) {
analogWrite(redLED1, redVal);
analogWrite(greenLED1, greenVal);
analogWrite(blueLED1, blueVal);
}
if (twoON == 1) {
analogWrite(redLED2, redVal);
analogWrite(greenLED2, greenVal);
analogWrite(blueLED2, blueVal);
}
if (threeON == 1) {
analogWrite(redLED3, redVal);
analogWrite(greenLED3, greenVal);
analogWrite(blueLED3, blueVal);
}
if (fourON == 1) {
analogWrite(redLED4, redVal);
analogWrite(greenLED4, greenVal);
analogWrite(blueLED4, blueVal);
}
}
// Interrupt routines to select from one of the four sides
void one() {
oneON = 1;
twoON = 0;
threeON = 0;
fourON = 0;
}
void two() {
oneON = 0;
twoON = 1;
threeON = 0;
fourON = 0;
}
void three() {
oneON = 0;
twoON = 0;
threeON = 1;
fourON = 0;
}
void four() {
oneON = 0;
twoON = 0;
threeON = 0;
fourON = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment