// Scott Clandinin - 2017
#define REDPIN 5
#define GREENPIN 3
#define BLUEPIN 6
void setup()
{
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
randomSeed(analogRead(0)); //set random seed off floating pin A0
analogWrite(BLUEPIN, 255);
delay(1000);
}
void loop()
{
int routine;
routine1();
// routine = random(1,4);
//
// switch(routine)
// {
// case 1:
// routine1();
// break;
//
// case 2:
// routine2();
// break;
//
// case 3:
// routine3();
// break;
//
// case 4:
// routine4();
// break;
// }
}
//******************************************************
// fading colours
//******************************************************
void routine1()
{
int r, g, b;
int FADESPEED = 10; // make this higher to slow down
// fade from blue to violet
for (r = 0; r < 255; r++)
{
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from violet to red
for (b = 255; b > 0; b--)
{
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from red to yellow
for (g = 0; g < 255; g++)
{
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
// fade from yellow to green
for (r = 255; r > 0; r--)
{
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from green to teal
for (b = 0; b < 255; b++)
{
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from teal to blue
for (g = 255; g > 0; g--)
{
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
}
//******************************************************
// changing colours
//******************************************************
void routine2()
{
int r, g, b;
analogWrite(REDPIN, 255); //RED
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);
delay(1000);
analogWrite(REDPIN, 200); //yellow
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 0);
delay(1000);
analogWrite(REDPIN, 255); //orange
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 0);
delay(1000);
analogWrite(REDPIN, 0); //green
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 0);
delay(1000);
analogWrite(REDPIN, 25); //teal
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 255);
delay(1000);
analogWrite(REDPIN, 0); //blue
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 255);
delay(1000);
analogWrite(REDPIN, 255); //purple
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 255);
delay(1000);
analogWrite(REDPIN, 255); //pink
analogWrite(GREENPIN, 50);
analogWrite(BLUEPIN, 50);
delay(1000);
}
//******************************************************
// fading blue
//******************************************************
void routine3()
{
int r, g, b;
int FADESPEED = 20; // make this higher to slow down
// fade to blue
for (b = 0; b < 255; b++)
{
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade out blue
for (b = 255; b > 0; b--)
{
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
}
//******************************************************
// strobe purple
//******************************************************
void routine4()
{
analogWrite(REDPIN, 255); //purple
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 255);
delay(100);
analogWrite(REDPIN, 0); //off
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);
delay(100);
}
Comments