led program has to display in seven segment display

Hi all,

I am new to this forum and started to use a ardunio.

Here i am using 24 digital outputs, 8 digital inputs, 2 interupts.

24 digital outputs are connecting to led, 8 inputs are connecting to IC 7447 for display the output in seven segment display, and 2 interrupts are connecting to push button.

I want to do some project in arduino, concept was i want to glow 24 leds in ardunio mega, one by one while pressing the push button. also if i pressed once the 1st led should ON, and second time when i was pressed, first led should off, second led should on. like that i want to do upto 24 leds. and while the first led on, it should show as 01 in the seven segment display, then if i pressed second button, it should go to previous state,like now the current status is 7th led is glowing and showing as 07 in the display, if i pressed second button a 6th led should on and display as 06..
This concept i want to use in interrupt concept..

Please help me out to sort out this program ... also guide me to move next level...

Thank you all guys...

Sounds like a programming problem to me.
What is there to "sort out"?
You write the program so it does what you want.

Connecting an LED to an output pin: Arduino Tutorial - Lesson 3 - Breadboards and LEDs

Connecting a button to an input pin: Arduino Tutorial - Lesson 5

If you want to use the 7447 BCD-to-Seven-Segment Decoder/Driver to drive your two digit display you will need one for each digit and you will need four OUTPUT pins for each.

johnwasser:
Connecting an LED to an output pin: Arduino Tutorial - Lesson 3 - Breadboards and LEDs

Connecting a button to an input pin: Arduino Tutorial - Lesson 5

If you want to use the 7447 BCD-to-Seven-Segment Decoder/Driver to drive your two digit display you will need one for each digit and you will need four OUTPUT pins for each.

Thank you very much for your valuable reply sir..I have studied the HTML link which you have sent.
And i learned to increment function on the ardunio. but i want to know how to use increment and decrement opertion on the same program..
please help me to sort out sir..

Ditch the obsolete 7447 and use two TPIC6C595, one per digit, use shiftOut() to send the data to be displayed.
Use 3 TPIC6C595s for the 24 LEDS, use shiftpOut() to send the data to be displayed.
Can use just 3 IO pins to control all 5 shift registers; clock to all, latch to all, serial data to 1st, then 1st to 2nd, 2nd to 3rd, etc.
2 input pins for buttons.
Do the whole thing with an Uno, Nano, or a Promini with FTDI Basic to load code into it. Way cheaper than a Mega.

Don't forget current limit resistors.
https://www.digikey.com/products/en/integrated-circuits-ics/logic-shift-registers/712?k=tpic6c595&k=&pkeyword=tpic6c595&pv1989=0&pv69=80&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=25

RJenith:
And i learned to increment function on the ardunio. but i want to know how to use increment and decrement opertion on the same program..

I'm sorry. I don't understand the question.

Hi all,

I have developed the code for increment and decrement concept but now i want to display on the seven segment display..
Here i will post my code below:

const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 18;
const int ledPins = {22,24,26};
int buttonPushCounter = 0;
int buttonState1 = 0;
int lastButtonState1 = 0;
int buttonPushCounter2 = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;
int buttonState3 = 0;
int lastButtonState3 = 0;
void setup() {

pinMode(buttonPin1, INPUT);
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
pinMode(26, OUTPUT);

Serial.begin(9600);

}

void loop() {

{

buttonState1 = digitalRead(buttonPin1);

if (buttonState1 != lastButtonState1) {

if (buttonState1 == HIGH) {

buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);

}
}

lastButtonState1 = buttonState1;

if ((buttonPushCounter - 2) % 3 == 0) {

digitalWrite(24, LOW);
digitalWrite(22, HIGH);
digitalWrite(26, LOW);

} if ((buttonPushCounter - 3) % 3 == 0) {

digitalWrite(24, HIGH);
digitalWrite(22, LOW);
digitalWrite(26, LOW);

} if ((buttonPushCounter - 4) % 3 == 0){

digitalWrite(22, LOW);
digitalWrite(24, LOW);
digitalWrite(26, HIGH);

}
{

buttonState2 = digitalRead(buttonPin2);

if (buttonState2 != lastButtonState2) {

if (buttonState2 == HIGH) {

buttonPushCounter--;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);

}
}

lastButtonState2 = buttonState2;
}

}
}

Please sort out my problem..

Thanks...

Please sort out my problem

Please sort out your code tags

There you go. All sorted out.

const int  IncrementButtonPin = 2;
const int  DecrementButtonPin = 3;

const int LED_COUNT = 3;
const int LedPins[LED_COUNT] = {22, 24, 26};

int ButtonPushCounter = 0;

boolean LastIncrementButtonState = 0;
boolean LastDecrementButtonState = 0;


void setup() {
  Serial.begin(9600);

  pinMode(IncrementButtonPin, INPUT);
  pinMode(DecrementButtonPin, INPUT);

  for (int i = 0; i < LED_COUNT; i++) {
    pinMode(LedPins[i], OUTPUT);
  }
}

void loop() {
  // Get inputs
  boolean incrementButtonState = digitalRead(IncrementButtonPin);
  boolean decrementButtonState = digitalRead(DecrementButtonPin);

  // Act on inputs
  if (incrementButtonState != LastIncrementButtonState) {
    LastIncrementButtonState = incrementButtonState;
    if (incrementButtonState == HIGH) {
      ButtonPushCounter++;
      Serial.println("Increment");
      Serial.print("number of button pushes:  ");
      Serial.println(ButtonPushCounter);
    }
  }

  if (decrementButtonState != LastDecrementButtonState) {
    LastDecrementButtonState = decrementButtonState;
    if (decrementButtonState == HIGH) {
      ButtonPushCounter--;
      Serial.println("Decrement");
      Serial.print("number of button pushes:  ");
      Serial.println(ButtonPushCounter);
    }
  }

  // Light the Lights
  for (int i = 0; i < LED_COUNT; i++) {
    digitalWrite(LedPins[i], (ButtonPushCounter % LED_COUNT) == i);
  }
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

You really need to start using these:

https://www.arduino.cc/en/Reference/Comments

Thanks to all...

I have done the coding for incrment and decrement with display..
Now the pending is i want to add one more button and whenever i am pressing that button all leds should be an off condition..

Here is my code:

const int  buttonPin1 = 2; 
const int  buttonPin2 = 3;  
const int ledPins[] = {22,24,26};
const int A = 5;
const int B = 6;
const int C = 7;
const int D = 8;
const int E = 9;
const int F = 10;
const int G = 11;
const int H = 12;
int buttonPushCounter = 0;   
int buttonState1 = 0;         
int lastButtonState1 = 0;  
int buttonPushCounter2 = 0;   
int buttonState2 = 0;         
int lastButtonState2 = 0;  

void setup() {
  
  pinMode(buttonPin1, INPUT);
  pinMode(22, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);  
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);    
 
      
 
    
Serial.begin(9600);
  

}

void loop() {
  
  
{
  
  buttonState1 = digitalRead(buttonPin1);

  if (buttonState1 != lastButtonState1) {
    
    if (buttonState1 == HIGH) {
      
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
      
    }
  }

  lastButtonState1 = buttonState1;

    if ((buttonPushCounter - 0) % 3 == 0) {
  
    digitalWrite(24, LOW);
    digitalWrite(22, HIGH);
    digitalWrite(26, LOW); 
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW); 
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(10, LOW); 
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
}   if ((buttonPushCounter - 1) % 3 == 0) {
    
    digitalWrite(24, HIGH);
    digitalWrite(22, LOW);
    digitalWrite(26, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW); 
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, HIGH); 
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    
}   if ((buttonPushCounter - 2) % 3 == 0){

    digitalWrite(22, LOW);
    digitalWrite(24, LOW);
    digitalWrite(26, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW); 
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH); 
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    
    
}
{
  
  buttonState2 = digitalRead(buttonPin2);

  if (buttonState2 != lastButtonState2) {
    
    if (buttonState2 == HIGH) {
      
      buttonPushCounter--;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
      
    }
  }

  lastButtonState2 = buttonState2;
}

}
}

Can you please guide me to where i can add and what logic i can use.