int Red = 9;
int Green = 10;
int Blue = 11;
int pwm = 3;
//^^^ Sets the variable to a port
byte LED = 225;
//^^^Sets the valeu for the PWM and gives it a name
void setup() {
pinMode(Red, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Blue, OUTPUT);
pinMode(pwm, OUTPUT);
}
//^^^Sets the variable as an output
void loop() {
//^^^Lets the code loop
analogWrite(pwm, LED);
//^^^Turns on LED
if(LED==225) {
analogWrite(Red,255 );
analogWrite(Green,0 );
analogWrite(Blue,0);
//^^^Sets RGB values for when code starts and LED is at full brightness
}
else if (LED >=225* .75) {
analogWrite(Red,50 );
analogWrite(Green,70 );
analogWrite(Blue, 200);
//^^^Sets RGB values for when LED is at 75%
}
else if (LED >= 255*0.5) {
analogWrite(Red, 70);
analogWrite(Green, 120);
analogWrite(Blue, 170);
//^^^Sets RGB values for when LED is at 50%
}
else if (LED >= 255*0.25) {
analogWrite(Red, 40);
analogWrite(Green, 20);
analogWrite(Blue, 250);
//^^^Sets RGB values for when LED is at 25%
}
else {
analogWrite(Red, 1);
analogWrite(Green, 99);
analogWrite(Blue, 0);}
//^^^If LED is below 25%
if (LED > 0) {
LED = LED - 50;
//^^^Code to lower pwm value which will cause code to run in different paths
}
delay(500);
//^^^Sets a delay before the code starts looping
}