Go Down

Topic: LED sequence help (Read 988 times) previous topic - next topic

JWPardee

im trying to build a LED sequence that is triggered by a push button...  i seem to only find "loops"   if i could build one that the chase speed is controlable some how....   can anyone help point me in the right direction as to where i can get info to build something along these lines?   thank you all...

hellonearthis

Can you diuscribe it some more, what would the user do and what would the result be?

JWPardee

im trying to do two things.... 

one would be "pull a trigger" and have a simple chase across a series of LED lights...one to the next....   

the second thing i would want to do (same system or a different build) be able to pull the trigger and go down the sequence one LED to the next down the series of LEDs    pull trigger, first LED lights up....pull again, first LED goes out, second comes on...etc

if i could do it through the same chip, that would be awesome...but if not, i would try to do each on seperate chips.... 

Graynomad

Write some code in the setup() function that does what you want with the LEDs, every time you reset the Arduino the code will run and you can test it.

When it works cut the code out and create a function from it. Then add code in loop() that tests for a button to be pressed and calls that function.

Code: [Select]
void fireLEDs () {
// your LED code here
}

void loop () {
    if (digitalRead(triggerPin) == HIGH)
       fireLEDs();
}


_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

JWPardee

what is the best set up for what i am trying to do?  im new at this....  thank you in advanced for helping point me in the right directions

Graynomad

Quote
what is the best set up

First question, how many LEDs?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

DVDdoug

Start simple and build from there...   Most "real" computer programs are written and debugged this way.

Take a look at the Arduino Language Reference and some of the associated examples.   You'll want to look at input/output (how to detect a button-push and how to turn-on an LED).   You'll also want to look how if-statements work.  (If the LED is off and I push the button, do something...)

And, you'll need to know a little about timing and delays.

I'd start by making a program  (sketch) that turns-on an LED when you push the button/switch and off when you release it.   Then, make a program that turns the LED on when you push the button once, and turns-off when you push the button again.  (Mechanical buttons "bounce" for a few milliseconds, so you'll need a delay for that one.)

Now, write a little sketch that sequences LEDs.  The Bitwise Operators and bits & Bytes  functions might also be helpful.  In binary (base 2), a looping 4-channel "chase" looks like this:

0001 (=1 decimal)
0010 (=2 decimal)
0100 (=4 decimal)
1000 (=8 decimal)
0001
0010
0100
1000
0001
0010
0100
1000...

Take a look at blikenlight Experiments.
Quote
if i could do it through the same chip, that would be awesome...but if not, i would try to do each on seperate chips.... 
You should be able to do both, depending on how many LEDs are in your sequence.   And, there are ways to increase the number of LEDs you can drive/control.




hellonearthis

#7
Mar 09, 2012, 09:30 am Last Edit: Mar 15, 2012, 04:04 pm by hellonearthis Reason: 1
I know some will freak out a little about the use for a Fritzing image,  but as a noob I found it really helped me understand the schematics.
Sorry if this causes anyone to stress out,  ok.

I got the basic hardware debounce worked out. Thanks to http://www.ikalogic.com/debouncing.php

Code: [Select]
void setup() {
 Serial.begin(9600);
 pinMode(2, INPUT);     // that orange wire
 pinMode(13, OUTPUT);
}
void loop() {
 boolean sensorValue = digitalRead(2);
 Serial.println(sensorValue);
 sensorValue=!sensorValue;  //  I inverse this so the LED is off when no button pressed and on when pressed.
 digitalWrite(13,sensorValue);
}


http://dduino.blogspot.co.nz/2012/03/arduino-button-debouncing.html  is a great article on debouncing.
It says "Changing the size of the cap will change how long it takes to charge, and thus, how long it takes the digital to become "HIGH"."

It also has the resistor at the ground end of the circuit.

JWPardee

i have built something similar to this before....but what im trying to do is push the button and have it trigger a squence of led lights to flash on, then off...one at a time....   atleast 6-10 LED lights 

hellonearthis

Sounds easy,  the basic logic is like this code.
Code: [Select]

viod setup()
{
for (int ledpin=2; ledpin <= 10; ledpin++)  // loop through 8 digital pins (2-10) setting them to output
      {
        pinMode(ledpin, OUTPUT);
      }
  pinMode(11,INPUT)  // The button is connected to pin 11
} // setup

void loop()
{
   boolean buttonState = digitalRead(11); // get button state
   buttonState =! buttonState;            // Invert button state to match logic
  if (buttonState == true){
    for (int ledpin=2; ledpin <= 10; ledpin++)  // loop through them 8 led pins
      {
        digitalWrite(ledpin,HIGH);  // turn led on
        delay(333)                       // wait 1/3 of a second
        digitalWrite(ledpin,LOW);  // turn led off
      }  // for
  }  // if button
} // loop


Go Up