Ive recently bought my self a arduino Mega 2560 and managed to get a sort of RANDOM function to work with different cases which go of by the number selected. My question is is there a way to also make a PWM sequence in such a case? so that the LED is fully light to dark and then the the next case starts? IS there a more random sequence wich i could then also expand if neccesary?
Mark.
int ledcolor = 0;
int a = 500; //this sets how long the stays one color for
int b = 2000;
int brightness = 255; // how bright the LED is
int fadeAmount = 25; // how many points to fade the LED by
void setup() { //this sets the output pins
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}
void loop() {
int ledcolor = random(1,16); //this randomly selects a number between 1 and 15
switch (ledcolor) {
case 1: //if ledcolor equals 1 then the led on pin 11 will turn on etc.
analogWrite(11, brightness);
brightness = brightness - fadeAmount; break;
case 2:
digitalWrite(10, HIGH);
delay(a);
digitalWrite(10, LOW);
break;
case 3:
digitalWrite(9, HIGH);
delay(a);
digitalWrite(9, LOW);
break;