Skip to content

Instantly share code, notes, and snippets.

@Quietfire
Last active June 30, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Quietfire/1f0ae6e8a05f17288bb93a77dae9be77 to your computer and use it in GitHub Desktop.
Save Quietfire/1f0ae6e8a05f17288bb93a77dae9be77 to your computer and use it in GitHub Desktop.
Skull Lamp RGB LED Controller
/*
This sketch is to control the functions of 2 RGB LEDs utilizing all of the PWM pins
on an Arduino
*/
// Pinouts for NANO
int lledRed = 11;
int lledBlue = 10;
int lledGreen = 9;
int rledRed = 6;
int rledBlue = 5;
int rledGreen = 3;
int buttonPin = 2;
int buttonState = 0;
int buttonPushCounter = 1;
void setup() {
pinMode(lledRed, OUTPUT);
pinMode(lledBlue, OUTPUT);
pinMode(lledGreen, OUTPUT);
pinMode(rledRed, OUTPUT);
pinMode(rledBlue, OUTPUT);
pinMode(rledGreen, OUTPUT);
pinMode(buttonPin, INPUT);
// Serial.begin(9600); //for initial testing of function calls
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonPushCounter > 131){
buttonPushCounter = 1;
}
if (buttonState == HIGH) {
buttonPushCounter++;
}
delay(500);
/* The following switch case determines what our LEDs shall do. We have 3 functions that can be
called in a number of ways. The first 2 numbers in the calls are the LED Colors. The functions
read the 1's digit as red, the 10's digit as Blue, and the 100's digit as Green. The functions are
written so that 1 or 2 colors will light up. Example, 11 lights red and blue to give Purple.
*/
switch (buttonPushCounter) {
case 1:
twinPulseGlow( 1, 1, 5, 0); //Red
break;
case 2:
twinPulseGlow( 10, 10, 5, 0); //Blue
break;
case 3:
twinPulseGlow( 100, 100, 5, 0); //Green
break;
case 4:
twinPulseGlow( 11, 11, 5, 0); // Purple
break;
case 5:
twinPulseGlow( 110, 110, 5, 0); //Teal
break;
case 6:
twinPulseGlow( 101, 101, 5, 0); //Sick Green
break;
case 7:
twinPulseGlow( 1, 10, 5, 0); //Red Blue
break;
case 8:
twinPulseGlow( 10, 1, 5, 0); //Blue Red
break;
case 9:
twinPulseGlow( 10, 100, 5, 0); //Blue Green
break;
case 10:
twinPulseGlow( 100, 10, 5, 0); //Green Blue
break;
case 11:
twinPulseGlow( 1, 11, 5, 0); //Red Purple
break;
case 12:
twinPulseGlow( 11, 1, 5, 0); //Purple Red
break;
case 13:
twinPulseGlow( 10, 11, 5, 0); //Blue Purple
break;
case 14:
twinPulseGlow( 11, 10, 5, 0); //Purple Blue
break;
case 15:
twinPulseGlow( 100, 11, 5, 0); //Green Purple
break;
case 16:
twinPulseGlow( 11, 100, 5, 0); //Purple Green
break;
case 17:
twinPulseGlow( 101, 11, 5, 0); //Sick Green Purple
break;
case 18:
twinPulseGlow( 11, 101, 5, 0); //Purple Sick Green
break;
case 19:
twinPulseGlow( 1, 110, 5, 0); //Red Teal
break;
case 20:
twinPulseGlow( 110, 1, 5, 0); //Teal Red
break;
case 21:
twinPulseGlow( 10, 110, 5, 0); //Blue Teal
break;
case 22:
twinPulseGlow( 110, 10, 5, 0); //Teal Blue
break;
case 23:
twinPulseGlow( 11, 110, 5, 0); //purple Teal
break;
case 24:
twinPulseGlow( 110, 11, 5, 0); //Teal purple
break;
case 25:
twinPulseGlow( 100, 110, 5, 0); //Green Teal
break;
case 26:
twinPulseGlow( 110, 100, 5, 0); //Teal Green
break;
case 27:
twinPulseGlow( 101, 110, 5, 0); //Sick Green Teal
break;
case 28:
twinPulseGlow( 110, 101, 5, 0); //Teal Sick Green
break;
case 29:
twinPulseGlow( 101, 1, 5, 0); //Sick Green Red
break;
case 30:
twinPulseGlow( 1, 101, 5, 0); //Red Sick Green
break;
case 31:
twinPulseGlow( 101, 10, 5, 0); //Sick Green Blue
break;
case 32:
twinPulseGlow( 10, 101, 5, 0); //Blue Sick Green
break;
case 33:
twinPulseGlow( 101, 100, 5, 0); //Sick Green Green
break;
case 34:
twinPulseGlow( 100, 101, 5, 0); //Green Sick Green ...... full color possibility I think
break;
case 35:
twinPulseGlow( 1, 10, 5, 1); //Red Blue Swap
break;
case 36:
twinPulseGlow( 10, 100, 5, 1); //Blue Green Swap
break;
case 37:
twinPulseGlow( 1, 11, 5, 1); //Red Purple Swap
break;
case 38:
twinPulseGlow( 10, 11, 5, 1); //Blue Purple Swap
break;
case 39:
twinPulseGlow( 100, 11, 5, 1); //Green Purple Swap
break;
case 40:
twinPulseGlow( 101, 11, 5, 1); //Sick Green Purple Swap
break;
case 41:
twinPulseGlow( 1, 110, 5, 1); //Red Teal Swap
break;
case 42:
twinPulseGlow( 10, 110, 5, 1); //Blue Teal Swap
break;
case 43:
twinPulseGlow( 11, 110, 5, 1); //purple Teal Swap
break;
case 44:
twinPulseGlow( 100, 110, 5, 1); //Green Teal Swap
break;
case 45:
twinPulseGlow( 101, 110, 5, 1); //Sick Green Teal Swap
break;
case 46:
twinPulseGlow( 101, 1, 5, 1); //Sick Green Red Swap
break;
case 47:
twinPulseGlow( 101, 10, 5, 1); //Sick Green Blue Swap
break;
case 48:
twinPulseGlow( 101, 100, 5, 1); //Sick Green Green Swap
break;
case 49:
crossEyedFade( 1, 1, 5, 0); //Red
break;
case 50:
crossEyedFade( 10, 10, 5, 0); //Blue
break;
case 51:
crossEyedFade( 100, 100, 5, 0); //Green
break;
case 52:
crossEyedFade( 11, 11, 5, 0); // Purple
break;
case 53:
crossEyedFade( 110, 110, 5, 0); //Teal
break;
case 54:
crossEyedFade( 101, 101, 5, 0); //Sick Green
break;
case 55:
crossEyedFade( 1, 10, 5, 0); //Red Blue
break;
case 56:
crossEyedFade( 10, 1, 5, 0); //Blue Red
break;
case 57:
crossEyedFade( 10, 100, 5, 0); //Blue Green
break;
case 58:
crossEyedFade( 100, 10, 5, 0); //Green Blue
break;
case 59:
crossEyedFade( 1, 11, 5, 0); //Red Purple
break;
case 60:
crossEyedFade( 11, 1, 5, 0); //Purple Red
break;
case 61:
crossEyedFade( 10, 11, 5, 0); //Blue Purple
break;
case 62:
crossEyedFade( 11, 10, 5, 0); //Purple Blue
break;
case 63:
crossEyedFade( 100, 11, 5, 0); //Green Purple
break;
case 64:
crossEyedFade( 11, 100, 5, 0); //Purple Green
break;
case 65:
crossEyedFade( 101, 11, 5, 0); //Sick Green Purple
break;
case 66:
crossEyedFade( 11, 101, 5, 0); //Purple Sick Green
break;
case 67:
crossEyedFade( 1, 110, 5, 0); //Red Teal
break;
case 68:
crossEyedFade( 110, 1, 5, 0); //Teal Red
break;
case 69:
crossEyedFade( 10, 110, 5, 0); //Blue Teal
break;
case 70:
crossEyedFade( 110, 10, 5, 0); //Teal Blue
break;
case 71:
crossEyedFade( 11, 110, 5, 0); //purple Teal
break;
case 72:
crossEyedFade( 110, 11, 5, 0); //Teal purple
break;
case 73:
crossEyedFade( 100, 110, 5, 0); //Green Teal
break;
case 74:
crossEyedFade( 110, 100, 5, 0); //Teal Green
break;
case 75:
crossEyedFade( 101, 110, 5, 0); //Sick Green Teal
break;
case 76:
crossEyedFade( 110, 101, 5, 0); //Teal Sick Green
break;
case 77:
crossEyedFade( 101, 1, 5, 0); //Sick Green Red
break;
case 78:
crossEyedFade( 1, 101, 5, 0); //Red Sick Green
break;
case 79:
crossEyedFade( 101, 10, 5, 0); //Sick Green Blue
break;
case 80:
crossEyedFade( 10, 101, 5, 0); //Blue Sick Green
break;
case 81:
crossEyedFade( 101, 100, 5, 0); //Sick Green Green
break;
case 82:
crossEyedFade( 100, 101, 5, 0); //Green Sick Green
break;
case 83:
crossEyedFade( 1, 10, 5, 1); //Red Blue Swap
break;
case 84:
crossEyedFade( 10, 100, 5, 1); //Blue Green Swap
break;
case 85:
crossEyedFade( 1, 11, 5, 1); //Red Purple Swap
break;
case 86:
crossEyedFade( 10, 11, 5, 1); //Blue Purple Swap
break;
case 87:
crossEyedFade( 100, 11, 5, 1); //Green Purple Swap
break;
case 88:
crossEyedFade( 101, 11, 5, 1); //Sick Green Purple Swap
break;
case 89:
crossEyedFade( 1, 110, 5, 1); //Red Teal Swap
break;
case 90:
crossEyedFade( 10, 110, 5, 1); //Blue Teal Swap
break;
case 91:
crossEyedFade( 11, 110, 5, 1); //purple Teal Swap
break;
case 92:
crossEyedFade( 100, 110, 5, 1); //Green Teal Swap
break;
case 93:
crossEyedFade( 101, 110, 5, 1); //Sick Green Teal Swap
break;
case 94:
crossEyedFade( 101, 1, 5, 1); //Sick Green Red Swap
break;
case 95:
crossEyedFade( 101, 10, 5, 1); //Sick Green Blue Swap
break;
case 96:
crossEyedFade( 101, 100, 5, 1); //Sick Green Green Swap
break;
case 97:
solidOn( 1, 1); //Red
break;
case 98:
solidOn( 10, 10); //Blue
break;
case 99:
solidOn( 100, 100); //Green
break;
case 100:
solidOn( 11, 11); // Purple
break;
case 101:
solidOn( 110, 110); //Teal
break;
case 102:
solidOn( 101, 101); //Sick Green
break;
case 103:
solidOn( 1, 10); //Red Blue
break;
case 104:
solidOn( 10, 1); //Blue Red
break;
case 105:
solidOn( 10, 100); //Blue Green
break;
case 106:
solidOn( 100, 10); //Green Blue
break;
case 107:
solidOn( 1, 11); //Red Purple
break;
case 108:
solidOn( 11, 1); //Purple Red
break;
case 109:
solidOn( 10, 11); //Blue Purple
break;
case 110:
solidOn( 11, 10); //Purple Blue
break;
case 111:
solidOn( 100, 11); //Green Purple
break;
case 112:
solidOn( 11, 100); //Purple Green
break;
case 113:
solidOn( 101, 11); //Sick Green Purple
break;
case 114:
solidOn( 11, 101); //Purple Sick Green
break;
case 115:
solidOn( 1, 110); //Red Teal
break;
case 116:
solidOn( 110, 1); //Teal Red
break;
case 117:
solidOn( 10, 110); //Blue Teal
break;
case 118:
solidOn( 110, 10); //Teal Blue
break;
case 119:
solidOn( 11, 110); //purple Teal
break;
case 120:
solidOn( 110, 11); //Teal purple
break;
case 121:
solidOn( 100, 110); //Green Teal
break;
case 122:
solidOn( 110, 100); //Teal Green
break;
case 123:
solidOn( 101, 110); //Sick Green Teal
break;
case 124:
solidOn( 110, 101); //Teal Sick Green
break;
case 125:
solidOn( 101, 1); //Sick Green Red
break;
case 126:
solidOn( 1, 101); //Red Sick Green
break;
case 127:
solidOn( 101, 10); //Sick Green Blue
break;
case 128:
solidOn( 10, 101); //Blue Sick Green
break;
case 129:
solidOn( 101, 100); //Sick Green Green
break;
case 130:
solidOn( 100, 101); //Green Sick Green
break;
}
}
void twinPulseGlow(int lLed, int rLed, int plsSpeed, int swapEyes){
/*
This function caused both LEDs to pulse together at the same rate.
lLed and rLed are the color inputs described before the switch case in the void loop.
plsSpeed is the rate of delay between steps on the PWM pins that are connected to the LEDs.
If you want faster edit the calls with a smaller number, slower use a larger number. My coding
has it always call at 5. Just my choice, I wrote the @#$%.
swapEyes is checked at the end of the up and down loops. If it is set to 1, then the colors for
lLed and rLed are switched. Nice simple effect.
*/
int tmp;
while(buttonState != HIGH){
buttonState = digitalRead(buttonPin);
for (int xCount = 50; xCount < 254; xCount++){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// this if is in several places throughout the funtions. It looks for a button press then
// turns of the LEDs and breaks out of the loop to return to the void loop for the next case call.
ledsOff();
break;
}
if (((lLed / 1U) % 10) == 1){
analogWrite(lledRed, xCount);
}
if (((lLed / 10U) % 10) == 1){
analogWrite(lledBlue, xCount);
}
if (((lLed / 100U) % 10) == 1){
analogWrite(lledGreen, xCount);
}
if (((rLed / 1U) % 10) == 1){
analogWrite(rledRed, xCount);
}
if (((rLed / 10U) % 10) == 1){
analogWrite(rledBlue, xCount);
}
if (((rLed / 100U) % 10) == 1){
analogWrite(rledGreen, xCount);
}
delay(plsSpeed);
}
for (int xCount = 254; xCount > 50; xCount--){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
ledsOff();
break;
}
if (((lLed / 1U) % 10) == 1){
analogWrite(lledRed, xCount);
}
if (((lLed / 10U) % 10) == 1){
analogWrite(lledBlue, xCount);
}
if (((lLed / 100U) % 10) == 1){
analogWrite(lledGreen, xCount);
}
if (((rLed / 1U) % 10) == 1){
analogWrite(rledRed, xCount);
}
if (((rLed / 10U) % 10) == 1){
analogWrite(rledBlue, xCount);
}
if (((rLed / 100U) % 10) == 1){
analogWrite(rledGreen, xCount);
}
delay(plsSpeed);
}
if (swapEyes == 1){
ledsOff();
tmp = lLed;
lLed = rLed;
rLed = tmp;
}
}
}
void crossEyedFade(int lLed, int rLed, int plsSpeed, int swapEyes){
/*
This function caused both LEDs to pulse opposed to each other at the same rate.
lLed and rLed are the color inputs described before the switch case in the the void loop.
plsSpeed is the rate of delay between steps on the PWM pins that are connected to the LEDs.
If you want faster edit the calls with a smaller number, slower use a larger number. My coding
has it always call at 5. Just my choice, I wrote the @#$%.
swapEyes is checked at the end of the up and down loops. If it is set to 1, then the colors for
lLed and rLed are switched. Nice simple effect.
*/
int tmp;
int yCount;
while(buttonState != HIGH){
buttonState = digitalRead(buttonPin);
yCount = 254;
for (int xCount = 25; xCount < 254; xCount++){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
ledsOff();
break;
}
if (((lLed / 1U) % 10) == 1){
analogWrite(lledRed, xCount);
}
if (((lLed / 10U) % 10) == 1){
analogWrite(lledBlue, xCount);
}
if (((lLed / 100U) % 10) == 1){
analogWrite(lledGreen, xCount);
}
if (((rLed / 1U) % 10) == 1){
analogWrite(rledRed, yCount);
}
if (((rLed / 10U) % 10) == 1){
analogWrite(rledBlue, yCount);
}
if (((rLed / 100U) % 10) == 1){
analogWrite(rledGreen, yCount);
}
delay(plsSpeed);
yCount = yCount - 1;
}
for (int xCount = 254; xCount > 25; xCount--){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
ledsOff();
break;
}
if (((lLed / 1U) % 10) == 1){
analogWrite(lledRed, xCount);
}
if (((lLed / 10U) % 10) == 1){
analogWrite(lledBlue, xCount);
}
if (((lLed / 100U) % 10) == 1){
analogWrite(lledGreen, xCount);
}
if (((rLed / 1U) % 10) == 1){
analogWrite(rledRed, yCount);
}
if (((rLed / 10U) % 10) == 1){
analogWrite(rledBlue, yCount);
}
if (((rLed / 100U) % 10) == 1){
analogWrite(rledGreen, yCount);
}
delay(plsSpeed);
yCount = yCount + 1;
}
if (swapEyes == 1){
ledsOff();
tmp = lLed;
lLed = rLed;
rLed = tmp;
}
}
}
void solidOn(int lLed, int rLed){
/*
straight up this function just turns on the colors that were called until the button is pushed
and the next call is made
*/
while(buttonState != HIGH){
buttonState = digitalRead(buttonPin);
if (((lLed / 1U) % 10) == 1){
analogWrite(lledRed, 254);
}
if (((lLed / 10U) % 10) == 1){
analogWrite(lledBlue, 254);
}
if (((lLed / 100U) % 10) == 1){
analogWrite(lledGreen, 254);
}
if (((rLed / 1U) % 10) == 1){
analogWrite(rledRed, 254);
}
if (((rLed / 10U) % 10) == 1){
analogWrite(rledBlue, 254);
}
if (((rLed / 100U) % 10) == 1){
analogWrite(rledGreen, 254);
}
}
ledsOff();
}
void ledsOff(){
// simply used to turn off all LEDs. There are several places that call for this.
analogWrite(lledRed,0);
analogWrite(lledBlue,0);
analogWrite(lledGreen,0);
analogWrite(rledRed,0);
analogWrite(rledBlue,0);
analogWrite(rledGreen,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment