7-segment display problems

Why doesn't this work? Shouldn't the display constatly switch between zero and one? It displays zero and does nothing else. Newbie here.

// C++ code
//

void loop() {
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
delay(1000);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
delay(1000);
}

Where in your code do you write any of the segments low?

1 Like

You must configure the pins you use, for example;

int a = 2;

or maybe

#define b 3

Then you must define the pin direction (input or output), for example;

  pinMode(c, OUTPUT);

Without a setup() function and no definitions/declarations of a, b, c, d, e or f, I don't see how that sketch can even compile, let alone run. Could you please explain how you got that to work even partially?

Try this skethc:

//--- insert codes to assign DPins for the segments: a - g
void setup()
{
    //insert codes to set directions of IO lines with which segments (a - g) are connected 
}

void loop()  //for CC-type 7-segment display devices
{
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    delay(1000);
    //---------------------
    digitalWrite(a, LOW);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    delay(1000);
}

here few guides on 7-segment display with Arduino

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.