Go Down

Topic: Twinkler Help (Read 162 times) previous topic - next topic


Anyone got any ideas of how to make this code i found do random multiple LEDs at time instead of just 1?

Code: [Select]
// LED twinkler: LEDs on pins 2 to 13. each with 470 ohams to ground pin
// Pot wiper to A0. ends to +5v and ground

int Pin = 0, Locpct = 0, activeLED = 0, onTime = 10, potPin = 0;

void setup(){
  // set pin mode and lights each led in sequance
  for(Pin = 2; Pin < 14; Pin++){

void loop(){
  //only one random LED on at a time when pot is above center
  while(analogRead(2) <= 511){
     onTime = map(analogRead(potPin),0,511,2,100);
     activeLED = (random(2,14));
     delay(random(onTime, onTime * 5));
  // LEDs on and Off Randomly when pot is below center
  while(analogRead(potPin) > 511){
    onTime = map(analogRead(2),512,1023,100,2);
    delay(random(onTime, onTime *5));


Change the code to have X amount of activeLEDs.
I recommend careful use of ctrl+c and ctrl+v.


Sorry it took so long to reply. I attempted what you said and i was unable to get it to work still. I did play around with the code and eventually with a couple of changes was able to get it to do what i wanted to.

Thank you for the help though. 

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131