help button press count


Could any one help me, I m a newbie.

I need to do a circuit with 2 push buttons, and 2 bars with 7 lights. every time I press the button 1 light of one bar lights up, sequentially.

Best regards

Do you know how to program an Arduino to turn on a led if you push a PB switch?
Do you know how to increment a counter if you push a PB switch?
Do you know about debouncing switches?
Have you ever used the switch/case programming sequence?
Would you draw us a schematic of your circuit.

Do you have light bars already? If so, what is their part number?

Are you making the light bars from individual LEDs? If so, get 2 shift registers and 14 current limit resistors. I'd recommend TPIC6B595 or TPIC6C595. The code to read button and send 0b00000001, 0b00000011, 0b00000111, ... 0b01111111
will be easy to do and send to the shift registers, and will keep the current from IO pins at safe levels (vs 14 LEDs at 20mA each = 280mA)


Thank you of the fast response, I know very very little about programing.
I ned help for all the code :frowning:

Best regards

The main idea, is:

Button 1 controls led bar with 7 leds (outs 0 to 6)
Button 2 controls leg bar with 7 leds (outs 7 to 14)

Press 1 time button 1 and the first led lights up, press 1 more time and the second led lights up, and so on.
Button 2 is the same.

Is this similar to your led bar?

hello LarryD,

I do not have a bar at the moment just simple leds.

Draw this out with the shift register datasheet and see if you can follow it.
Look up the command used on the Reference page and the Library page for SPI.

#include <SPI.h>
byte button2 = 2;
byte button3 = 3;

byte ledArray[] = {0b00000001, 0b00000011, 0b00000111, 0b00001111, 0b00011111, 0b00111111, 0b01111111, 0,}; // ledArray[0] to ledArray[7]

byte index2 = 0; 
byte index3 = 0; 
byte ssPin2 = 9; // shift register output latch pin
byte ssPin3 = 10;

void setup(){
pinMode (button2, INPUT_PULLUP); // connect button to pin 2 and Gnd
pinMode (button3, INPUT_PULLUP); // connect button to pin 3 and Gnd
pinMode (sspin2, OUTPUT);
digitalWrite (ssPin2, HIGH);
pinMode (sspin3, OUTPUT);
digitalWrite (ssPin3, HIGH);

SPI.begin();  // sets up SPI hardware, pins 11-12-13

void loop(){
if (digitalRead(button2) == LOW){ // button pressed?
digitalWrite (ssPIN2, LOW);
SPI.transfer(ledArray[index2]); // send data shift register
digitalWrite (ssPin2, HIGH); // outputs change on this rising edge
index2= index2 + 1;
if (index2==8){index2 = 0;} // cycled thru all LEDs on and then off? reset to start again

if (digitalRead(button3) == LOW){
digitalWrite (ssPIN3, LOW);
digitalWrite (ssPin3, HIGH);
index3= index3 + 1;
if (index3==8){index3 = 0;}
// delay(100); // limits button presses to 10/second

Shift register:
MSCLR to +5V
OE/ to Gnd
Arduino pin 9 to RCLK on one part
Arduino pin 10 to RCLK on the other part
Arduino pin 11 to Serial Data in on both parts
Arduino pin 13 to SRCLK on both parts

LEDs: +5 to anode, cathode to current limit resistor, other side of resistor to a shift register output

What Arduino board do you have?

You have 14 LEDs and two monentary push button switches?
Do you have fourteen 220 ohm resistors?


Thank you of the fast response, I know very very little about programing.
I ned help for all the code :frowning:

Best regards

When is our assignment due to be handed in ?
How many of the example programs in the IDE have you run ?

Do you know anything about LEDs?

Hello All,

I have done some experiments but no success, Is any one able to help me in this situation, developing all the programming an drawing the implementation circuit, I could pay for you time.

I already have a Arduino duemilenove, leds, resistance's, and bush buttons.

Best Regards

Start simple.

Connect the cathode (negative end, probably the shorter lead) of one of the LEDs to pin 10 of the Arduino and the other lead of the LED to 5V via one of your resistors.

Upload this program to the Arduino.

const byte ledPin = 10;

void setup()
  pinMode(ledPin, OUTPUT);

void loop()
  digitalWrite(ledPin, !digitalRead(ledPin));

Does the LED turn on and off ?