I have try to do a program as below & I want to do a flowcharts of showSpectrum & show RGB, anyone can guide me how to do it.
const int RED_PIN = 75;
const int GREEN_PIN = 76;
const int BLUE_PIN = 77;
int DISPLAY_TIME = 100;
void setup()
{
// put your setup code here, to run once:
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
mainColours();
showSpectrum();
}
void mainColours()
{
// off all LEDs
digitalWrite(RED_PIN,LOW);
digitalWrite(GREEN_PIN,LOW);
digitalWrite(BLUE_PIN,LOW);
delay(1000); //Delay for 1 second
// On RED only
digitalWrite(RED_PIN,HIGH);
digitalWrite(GREEN_PIN,LOW);
digitalWrite(BLUE_PIN,LOW);
delay(1000); //Delay for 1 second
// On GREEN only
digitalWrite(RED_PIN,LOW);
digitalWrite(GREEN_PIN,HIGH);
digitalWrite(BLUE_PIN,LOW);
delay(1000); //Delay for 1 second
// On BLUE only
digitalWrite(RED_PIN,LOW);
digitalWrite(GREEN_PIN,LOW);
digitalWrite(BLUE_PIN,HIGH);
delay(1000); //Delay for 1 second
// On YELLOW only
digitalWrite(RED_PIN,HIGH);
digitalWrite(GREEN_PIN,HIGH);
digitalWrite(BLUE_PIN,LOW);
delay(1000); //Delay for 1 second
// On CYAN only
digitalWrite(RED_PIN,LOW);
digitalWrite(GREEN_PIN,HIGH);
digitalWrite(BLUE_PIN,HIGH);
delay(1000); //Delay for 1 second
// On PURPLE only
digitalWrite(RED_PIN,HIGH);
digitalWrite(GREEN_PIN,LOW);
digitalWrite(BLUE_PIN,HIGH);
delay(1000); //Delay for 1 second
// On ALL only
digitalWrite(RED_PIN,HIGH);
digitalWrite(GREEN_PIN,HIGH);
digitalWrite(BLUE_PIN,HIGH);
delay(1000); //Delay for 1 second
}
void showSpectrum()
{
int x;
for(x = 0; x < 768; x++)
{
showRGB(x);
delay(10);
}
}
void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;
if (color <= 255) // zone 1
{
redIntensity = 255 - color; // redgoes from on to off
greenIntensity = color; // green goes fromoff to on
blueIntensity = 0; // blue is always off
}
else if (color <= 511) //zone 2
{
redIntensity = 0; // red is always off
greenIntensity = 255 - (color - 256); // green on to off
blueIntensity = (color - 256); // blue off to on
}
else // color >= 512 // zone3
{
redIntensity = (color - 512); // red if off to on
greenIntensity = 0; // green is always off
blueIntensity = 255 - (color - 512); // blue off to on
}
analogWrite(RED_PIN, redIntensity);
analogWrite(GREEN_PIN, greenIntensity);
analogWrite(BLUE_PIN, blueIntensity);
}