7 segment display

I am trying to build a 3 7- segment display that will continuously display data based on some input parameters. If i declare the value to be displayed in the global area, LED works fine. But I am unable to display any useful information when the value to be displayed changes inside loop() or any other function.

What should I do?
I

What should I do?

I am getting very fed up saying this.

POST YOUR CODE !

I have attached the code!

LEDdisplay.ino (5.69 KB)

Hermoine:
I have attached the code!

Thank you. I don't want to seem ungrateful, but it would have been easier to provide help if you had copied it into a post.

I can do that!

const int inputPin = 2; // the pin that the pushbutton is attached to

int inputHighCounter = 4; // counter for the number of button presses
int inputState = 0; // current state of the button
int lastInputState = 0; // previous state of the button
unsigned long startTime=0;
unsigned long stopTime=0;
unsigned long period=0;
int digit=78;//if defined here, i get sensible output on display
int var=78;
int no_of_digits=0;
int digitArr[4];
int frequency;
void calc(int st, int sp);
void Num_Write(int display_digit[]);
int num_array[10][7]={{ 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,0,0,1,1 }}; // 9
int frequency_display[4][4]={{1,1,1,0},{1,1,0,1},{1,0,1,1},{0,1,1,1}};

void setup() {
// initialize the button pin as a input:
pinMode(inputPin, INPUT);
// initialize the LED as an output:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);//dot pin
pinMode(22, OUTPUT);//MSB bit 5/8 connected
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);

// initialize serial communication:
//Serial.begin(57600);
}

void loop() {
// read the pushbutton input pin:
// inputState = digitalRead(inputPin);
//
// // compare the buttonState to its previous state
// if (inputState != lastInputState) {
// // if the state has changed, increment the counter
// if (inputState == HIGH) {
// // if the current state is HIGH then the button
// // wend from off to on:
// if(inputHighCounter % 2 == 0){
// startTime = millis();
// inputHighCounter++;
// }
// else{
// stopTime =millis();
// inputHighCounter++;
// }
// }
// }
//// // save the current state as the last state,
//// //for next time through the loop
// lastInputState = inputState;
////
////
//// // turns on the LED every four button pushes by
//// // checking the modulo of the button push counter.
//// // the modulo function gives you the remainder of
//// // the division of two numbers:

// if (inputHighCounter != 2 && inputHighCounter % 2 == 0) {
// period = stopTime-startTime;
frequency = 345;
// var=frequency; UNABLE TO MODIFY
// digit=frequency;
//calc(stopTime,startTime);

//calc(var,digit);
while(var){
var=(var/10);
no_of_digits++;
}
if(no_of_digits > 2){
int divider=pow(10,no_of_digits-2);
int divider2=pow(10,no_of_digits-3);
digitArr[3]= digit/pow(10,no_of_digits-1);
digitArr[2]= (digit/divider) % 10;
digitArr[1]= (digit/divider2) % 10;
digitArr[0]= no_of_digits-3;
}
else{
digitArr[3]= 0;
digitArr[2]= digit/10;
digitArr[1]= digit % 10;
digitArr[0]= (digit*10)%10;
}

Num_Write(digitArr);
//delay(100);
// var=frequency+2;
// digit=frequency+2;

}}

void calc(int v,int d)
{int var;
int digit;
var=v;
digit=d;
while(var){
var=(var/10);
no_of_digits++;
}
if(no_of_digits > 2){
int divider=pow(10,no_of_digits-2);
int divider2=pow(10,no_of_digits-3);
digitArr[3]= digit/pow(10,no_of_digits-1);
digitArr[2]= (digit/divider) % 10;
digitArr[1]= (digit/divider2) % 10;
digitArr[0]= no_of_digits-3;
}
else{
digitArr[3]= 0;
digitArr[2]= digit/10;
digitArr[1]= digit % 10;
digitArr[0]= (digit*10)%10;
}
Num_Write(digitArr);
}
void Num_Write(int display_digit[]){

for(int i=0; i<4; i++){
int ledSegmentPin=3;
int selectSegmentPin=22;
for(int j=0; j<7; j++){
digitalWrite(ledSegmentPin,num_array[display_digit*][j]);*

  • ledSegmentPin++;*
  • }*
  • for(int k=0; k<4; k++){*
    digitalWrite(selectSegmentPin,frequency_display*[k]);
    _
    selectSegmentPin++;_
    _
    }_
    _
    if(i==0){_
    _
    digitalWrite(10,1);_
    _
    }_
    _
    delay(3);_
    _
    }_
    _
    }*_

Thank you again but, oh dear, why is some of the code in italics ? It's because you did not put code tags round it. Edit your post, select the code then click the code tags icon (</>) top/left of the editor before you save the code. Even better remove all of the commented lines and in the IDE use Ctrl/T to format the code before posting it here.

Sorry if I sound picky but if you present your code in the best way possible then there is more chance of getting help.