Go Down

Topic: Advanced Blink modification (Read 1 time) previous topic - next topic

islandbehr

I found following and want to modify it to handle 6+ ledpins.

Quote

/*
Advanced Blink Sketch
By: David M. Orlo
www.DaviedOrlo.com
*/
byte SWITCHPIN= 2; //Set Pin 2 as Switch
byte LEDPIN = 6; //Set Pin 6 as LED
byte brightness; //Create a Integer variable named brightness
byte delayedoff; //Create a Integer variable named delayedoff
byte delayedon; //Create a Integer variable named delayedon
//If you want to go higher than 255 you must change from "byte" to "int"
boolean buttonstate; //Create a Integer variable named buttonstate
 
void setup()
{
pinMode(SWITCHPIN, INPUT); //Set Pin 2 as Input
pinMode(LEDPIN, OUTPUT); //Set Pin 6 as Output
}
 
void loop()
{
buttonstate = digitalRead(SWITCHPIN); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
{
crazyLED(); //Now we go into a new function called crazyLED
}
}
 
void crazyLED()//crazyLED function we created and called whatever we want
{
buttonstate = LOW; //First we tell the micro the switch is now LOW
delay(250);
while (buttonstate == LOW) //White the switch is NOT pressed we do the following
{
buttonstate = digitalRead(SWITCHPIN); //Continually look at the switch to see if its pressed
brightness = random(1, 254); //Generates a random number from 1-254 and assigns it to the variable named brightness
delayedoff = random(1, 125); //Generates a random delay and assigns it to the variable named delayed
delayedon = random(1, 250); //Generates a random delay and assigns it to the variable named delayed
analogWrite(LEDPIN, brightness); //Uses the random number we generated to write the value to our LED
delay(delayedon); //random delay on time
analogWrite(LEDPIN, 0); //We turn the LED off for a blinking effect
delay(delayedoff); //Random delay off time
}
//Once the switch is pressed again we break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(LEDPIN, 0); //We turn the LED off before leaving our custom function
delay(500);
}

[/sub]

Thank you very much for any help you can give.

pYro_65

You should check out http://arduino.cc/en/Tutorial/BlinkWithoutDelay

If you need to independently control the led's, delay() will make it quite difficult.
Also, you will want to check the power requirements for how ever many led's will be lit at once. You may need a secondary power supply to handle more than a couple at once.

Or check out multiplexing which uses only one led at a time, but super fast, giving the impression of multiple led's lit up. You can even control the individual brightness.
Forum Mod anyone?
https://arduino.land/Moduino/

Go Up