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
xfpd
January 6, 2024, 3:11am
3
sketmen2:
Why doesn't this work
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?
sketmen2:
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);
}
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);
}
system
Closed
July 6, 2024, 5:21pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.