LED Bar graph and Button

I've looked and looked I can't seem to find anything to tell me how I can use a LED Bar graph and a button to advance
from one light to the next...
Here is what I'm trying to accomplish...

Any help would be much appreciated...
Thanks
Michael

How have you wired it up yourself?

That is not my video...
I want to replicate what is in the video but I have to use a regular LED Bar graph
I don't have SMD LED's...
I want 2 buttons one to go up and one to go down and the other modes...
I can use a Arduino Nano but I don't know how to use it for the buttons...
Thanks
Michael

There are plenty of examples out there for how to use pushbutton switches.

You could use one to increment and one to decrement a counter and print the result using Serial Monitor for starters.

I've been looking for examples...
I have one on my breadboard now I just can't get it to go more than 2 LED's...
And what you said about serial monitors is way over my head...
Here is the example I was using...

/* YourDuinoStarter Example: Button Input
 - Reads state of Pushbutton, changes state of 2 LEDS
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
 - Pushbutton Switch from +5 to Pin 3
 - 10K Resistor from Pin 3 to ground
 - LED and 220 ohm resistor in series from pins 10 and 11 to Gnd
 - V1.00 09/17/12
 Questions: terry@yourduino.com */

/*-----( Declare Constants and Pin Numbers )-----*/
#define buttonPin  3    // Pins to connect to
#define ledPin1    10
#define ledPin2    11

void setup()   /****** SETUP: RUNS ONCE ******/
{
  pinMode (ledPin1,OUTPUT) ;        // PIN 10 is an OUTPUT    
  pinMode (ledPin2, OUTPUT) ;       // PIN 11 is an OUPUT
  pinMode (buttonPin, INPUT) ;      // PIN 3  is an INPUT
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if  (digitalRead(buttonPin)==HIGH)  // IF button is pushed
  {
    digitalWrite(ledPin1, HIGH) ;         // LED1 ON
    digitalWrite(ledPin2, LOW) ;          // LED2 OFF
  }  
  else 
  {
    digitalWrite(ledPin1, LOW) ;          // LED1 OFF
    digitalWrite(ledPin2, HIGH) ;         // LED2 ON
  }
  delay(50);  // Switch may be "bouncing". Wait a bit

}//--(end main loop )---

I just don't know what i'm doing with this...

jameskirk:
And what you said about serial monitors is way over my head...

Adding --
http://www.newtechandme.com/arduino/arduino-tutorials-lesson-2-3-counter-using-increment-and-decrement-buttons/

Ok this is what I have so far...
I'm starting out with 1 switch to see how that works...
Here is the sketch I'm using...

const int LED1=12;
const int LED2=11;
const int LED3=10;
const int LED4=9;
const int LED5=8;
const int LED6=6;
const int LED7=5;
const int LED8=4;
const int LED9=3;
const int LED10=2;
const int SW=7;
boolean state = true; // declare variable state as boolean
int val=0;

void setup()
{
  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(LED4,OUTPUT);
  pinMode(LED5,OUTPUT);
  pinMode(LED6,OUTPUT);
  pinMode(LED7,OUTPUT);
  pinMode(LED8,OUTPUT);
  pinMode(LED9,OUTPUT);
  pinMode(LED10,OUTPUT);
  pinMode(SW,INPUT);
 }
void loop()
{
  val=digitalRead(SW);
  delay(100); // Software debouncing

if(val==HIGH)

{state=!state; // Complimenting the status of LED
  digitalWrite(LED1,state);
  digitalWrite(LED2,!state);
  digitalWrite(LED3,!state);
  digitalWrite(LED4,!state);
  digitalWrite(LED5,!state);
  digitalWrite(LED6,!state);
  digitalWrite(LED7,!state);
  digitalWrite(LED8,!state);
  digitalWrite(LED9,!state);
  digitalWrite(LED10,!state);
}
}

I can't get it to advance from one LED to the next...
There is a problem with the state lines at the bottom...
I don't know how to correct it any thoughts???
here is 3 pics of the layout...


Thanks
Michael

Hi again Michael,

Your sketch only has one "state" variable, which can only be HIGH or LOW. All 10 of your LEDS are tied to that one variable. 9 of them are on when state is LOW and 1 is on when state is HIGH. The 9 that are on when state is LOW will always be either on or off together.

To have individual control over 10 leds, you need either 10 "state" variables (these could be in an array), or a number variable that can change value from 0 to 10 (rather than just HIGH or LOW) to indicate how many leds should be on.

Paul

PS. CODE TAGS, C'MON MICHAEL, CODE TAGS PLEASE!

Try something like this... compiles but is untested.

note the use of the array... much simpler.

int ledPins[10] = {12,11,10,9,8,6,5,4,3,2};
const int pushButton=7;
int lastVal;
int index;
int increment = 1;

void setup()
{
  for (int i = 0; i < 10; i++)
  {
    pinMode(ledPins[i],OUTPUT);
  }
  pinMode(pushButton,INPUT);
}
void loop()
{
  int val=digitalRead(pushButton);
  delay(50); // Software debouncing
  if(val==HIGH && lastVal == LOW)
  {
    index += increment;
    if (index <=0 || index >= 9) increment = -increment;
    for (int i = 0; i < 10; i++)
    {
      if (i <= index) digitalWrite(ledPins[i], HIGH);
      else digitalWrite(ledPins[i], LOW);
    }
  }
  lastVal = val;  
}

PaulRB Sorry for the way I posted my code...
I didn't know any better I had to Google code tags so now I know
I corrected the code postings...

BulldogLowell Thanks for the code I will try it...
Thanks
Michael

jameskirk:
I didn't know any better I had to Google code tags so now I know

Thanks for correcting your posts Michael. I did explain about code tags before when we were working on your Klingon photon collector, glad you finally understand!

PS. That Star Trek movie was on TV here a couple of weeks ago. The photon collector is not Klingon. It was made by Spock and Scotty from parts found on the Klingon ship I think...

Paul

Yes Paul you are correct...

BulldogLowell I tried the code that you posted...
I tried editing it to no avail...
Is there a way when it counts up and it comes back down it goes completely off instead of just to one???
Also I would like to use 2 buttons one to count from 0 up to 10 and the other to count from 10 down to 0...
Here is a video of what I have now

Thanks
Michael

another way would be to use bitRead()

I compiled but couldn't test this, try it and let me know!

//
int ledPins[10] = {12,11,10,9,8,6,5,4,3,2};
int ledArray[11] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF};
const int pushButton=7;
int lastVal;
int index = 0;
int increment = 1;

void setup()
{
  Serial.begin(115200);
  for (int i = 0; i < 11; i++)
  {
    Serial.println(ledArray[i], BIN);
  }
  for (int i = 0; i < 11; i++)
  {
    pinMode(ledPins[i],OUTPUT);
  }
  
  pinMode(pushButton,INPUT);
}
void loop()
{
  int val=digitalRead(pushButton);
  delay(50); // Software debouncing
  if(val==HIGH && lastVal == LOW)
  {
    index += increment;
    if (index <=0 || index >= 10) increment = -increment;
    Serial.print("index = "); Serial.println(index);
    for (int i = 0; i < 10; i++)
    {
      digitalWrite(ledPins[i], bitRead(ledArray[index], i));
    }
  }
  lastVal = val;  
}

two buttons for up and down... using bitShift()...

not tested...

int ledPin[10] = {12,11,10,9,8,6,5,4,3,2};
const int pushButton  = 7;
const int pushButton2 = 13;
int lastVal;
int lastVal2;
int index = 0;

void setup()
{
  Serial.begin(115200);
  for (int i = 0; i < 11; i++)
  {
    pinMode(ledPin[i],OUTPUT);
  }
  pinMode(pushButton,INPUT);
  pinMode(pushButton2,INPUT);
}
void loop()
{
  int val=digitalRead(pushButton);
  delay(50); // Software debouncing
  if(val==HIGH && lastVal == LOW)
  {
    index <<= 1;
    index |= 1;
    if (index > 0b1111111111) index = 0b1111111111;
    Serial.print("index = "); Serial.println(index, BIN);
    for (int i = 0; i < 10; i++)
    {
      digitalWrite(ledPin[i], bitRead(index, i));
    }
  }
  lastVal = val;
  int val2 = digitalRead(pushButton2);
  delay(50); // Software debouncing
  if(val2 == HIGH && lastVal2 == LOW)
  {
    index >>= 1;
    Serial.print("index = "); Serial.println(index, BIN);
    for (int i = 0; i < 10; i++)
    {
      digitalWrite(ledPin[i], bitRead(index, i));
    }
  }
  lastVal2 = val2;
}

Here is a video of how it turned out...

Now all I need is a tone with each touch of the buttons...
Thanks
Michael

works great! 8)

did you use my latest post?

Yes I did works GREAT...
Now I just need to add a tone to the buttons...
Thanks
Michael

Here is a video of the Tone with the buttons...

Thanks
Michael

I would like to add 2 other sequences to the sketch if it is possible...
It will be like a diagnostic mode and a overload mode...
I found this sketch that I would like to put in when
all the LEDs are lit up so if I push the button 11 times it will put it in diagnostic mode...
If I would push the buttons like on the video it would put it in overload mode...
Here is the video...

Here is the code I found...

/*
 * inAndOut() - This will turn on the two middle LEDs then the next two out
 * making an in and out look
 */
void inAndOut(){
  int delayTime = 100; //the time (in milliseconds) to pause between LEDs
                       //make smaller for quicker switching and larger for slower
  
  //runs the LEDs out from the middle
  for(int i = 0; i <= 3; i++){
    int offLED = i - 1;  //Calculate which LED was turned on last time through
    if(i == 0) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will
      offLED = 3;        //turn on LED 2 and off LED 1)
    }                    //however if i = 0 we don't want to turn of led -1 (doesn't exist)
                         //instead we turn off LED 7, (looping around)
    int onLED1 = 3 - i;       //this is the first LED to go on ie. LED #3 when i = 0 and LED 
                             //#0 when i = 3 
    int onLED2 = 4 + i;       //this is the first LED to go on ie. LED #4 when i = 0 and LED 
                             //#7 when i = 3 
    int offLED1 = 3 - offLED; //turns off the LED we turned on last time
    int offLED2 = 4 + offLED; //turns off the LED we turned on last time
    
    digitalWrite(ledPins[onLED1], HIGH);
    digitalWrite(ledPins[onLED2], HIGH);    
    digitalWrite(ledPins[offLED1], LOW);    
    digitalWrite(ledPins[offLED2], LOW);        
    button_delay(delayTime, buttonPin);
  }
 
  //runs the LEDs into the middle
  for(int i = 3; i >= 0; i--){
    int offLED = i + 1;  //Calculate which LED was turned on last time through
    if(i == 3) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will
      offLED = 0;        //turn on LED 2 and off LED 1)
    }                    //however if i = 0 we don't want to turn of led -1 (doesn't exist)
                         //instead we turn off LED 7, (looping around)
    int onLED1 = 3 - i;       //this is the first LED to go on ie. LED #3 when i = 0 and LED 
                             //#0 when i = 3 
    int onLED2 = 4 + i;       //this is the first LED to go on ie. LED #4 when i = 0 and LED 
                             //#7 when i = 3 
    int offLED1 = 3 - offLED; //turns off the LED we turned on last time
    int offLED2 = 4 + offLED; //turns off the LED we turned on last time
    
    digitalWrite(ledPins[onLED1], HIGH);
    digitalWrite(ledPins[onLED2], HIGH);    
    digitalWrite(ledPins[offLED1], LOW);    
    digitalWrite(ledPins[offLED2], LOW);        
    button_delay(delayTime,buttonPin);
  }
}]

Any help would great...
Thanks
Michael