Create a gist now

Instantly share code, notes, and snippets.

Arduino code for my Halloween mask. It controls some RGB LEDs and some red diffused LEDs.
// Mood Lamp
float RGB1[3];
float RGB2[3];
float INC[3];
int red, green, blue;
const int redPin = 11; //eyes red
const int greenPin = 10; //eyes green
const int bluePin = 9; //eyes blue
const int fader = 5; //fin leds
void setup(){
RGB1[0] = 0;
RGB1[1] = 0;
RGB1[2] = 0;
RGB2[0] = random(256);
RGB2[1] = random(256);
RGB2[2] = random(256);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(fader, OUTPUT);
//main loop
void loop(){
for(int i=0;i<5;i++){
yellow_eyes(250, 250, 210); //turn on yellow eyes. can set any RGB value.
fin_fader(30, 40); //pulsate red LEDs. 30ms to fade in, 40ms to fade out.
digitalWrite(fader, HIGH); //turn on red LEDs
for(int i=0;i<50;i++){
mood_mode(); //iterate through RGB colours
digitalWrite(fader, LOW); //turn off red LEDs
//function to set the color for the eyes
void yellow_eyes(int R, int G, int B){
analogWrite(redPin, R);
analogWrite(greenPin, G);
analogWrite(bluePin, B);
//function to pulsate the red LEDs
void fin_fader(int fade_in, int fade_out){
int i = 0;
analogWrite(fader, i);
i = i+5;
i = 255;
analogWrite(fader, i);
i = i-5;
digitalWrite(fader, LOW);
//changing RGB eye colors
void mood_mode(){
for (int x=0; x<256; x++){
INC[x] = (RGB1[x] - RGB2[x]) / 256;
for (int x=0; x<256; x++){
red = int(RGB1[0]);
green = int(RGB1[1]);
blue = int(RGB1[2]);
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
RGB1[0] -= INC[0];
RGB1[1] -= INC[1];
RGB1[2] -= INC[2];
for (int x=0; x<3; x++){
RGB2[x] = random(556)-300;
RGB2[x] = constrain(RGB2[x], 0, 255);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment