I’m using a common anode display and the topmost segment won’t light up. Please help.
Please don’t ask if there are problems in the hardware, for the wirings are working (I’ve tested the other wires that are used in the working segments, the Arduino itself is working ( I’ve tested changing the pins) The 7 Segment display is working as I’ve tried changing one of the working output wires into the seems-to-be “not working” topmost segment. The breadboard is working, I’ve tried changing the position of the 7 segment display, and other 6 segments are working, leaving the segA or the topmost segment not working.
The code includes a servo motor and a 7 segment display. The setup works in a way that when the push button is HIGH in “IN”, the 7 segment display decrements from 9 to one, one by one everytime the push button is hit. when the push button is HIGH in “OUT” the 7 segment display increments from one to 9, one by one everytime the push button is hit. I’ve got no problem with the mechanism, but I’ve got problems with the display of the digit, the topmost segment of the 7 segment display does not light up with any value. PLEASE HELPPP!!!
This is the code I’ve modified from Arduining.com
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define ServoM 12 //Connected to the servo motor.
#define Bright 11 //servo library disable PWM on pins 9 and 10.
#define Exit 9 //Pin connected to the EXIT button.
#define In 8 //Pin connected to the IN button.
#define BarLow 90 //Low position of the barrier.
#define BarUp 160 //Up position of the barrier.
#define CAPACITY 9 //Capacity of the parking lot.
#define INTEN 80 //Display intensity %
//Pins conections to segments (cathodes).
#define segA 0
#define segB 1
#define segC 2
#define segD 3
#define segE 4
#define segF 5
#define segG 6
//Array with the segments to represent the decimal numbers (0-9).
byte segments[10] = {
// pgfedcba <--- segments
B11000000, // number 0
B11111001, // number 1
B10100100, // number 2
B10110000, // number 3
B10011001, // number 4
B10010010, // number 5
B10000010, // number 6
B11111000, // number 7
B10000000, // number 8
B10010000 // number 9
};
void setup(){
myservo.attach(ServoM); // attaches the servo.
pinMode(Exit, INPUT); // set "EXIT" button pin to input
pinMode(In, INPUT); // set "IN" button pin to input
digitalWrite(Exit, HIGH); // Connect Pull-Up resistor.
digitalWrite(In, HIGH); // Connect Pull-Up resistor.
pinMode(segA,OUTPUT);
pinMode(segB,OUTPUT);
pinMode(segC,OUTPUT);
pinMode(segD,OUTPUT);
pinMode(segE,OUTPUT);
pinMode(segF,OUTPUT);
pinMode(segG,OUTPUT);
pinMode(Bright,OUTPUT);
analogWrite(Bright,255*INTEN/100);
myservo.write(BarLow); //Barrier in the low position
// delay(1000);
}
int Available= 9; // Number of places available.
//================================================================
void loop(){
Display(Available);
if(digitalRead(In)==0)
{
if(Available != 0){
Available--;
myservo.write(BarUp);
delay(3000);
myservo.write(BarLow);
}
}
if(digitalRead(Exit)==0)
{
if(Available != CAPACITY){
Available++;
myservo.write(BarUp);
delay(3000);
myservo.write(BarLow);
}
}
}
/*-------------------------------------------------------------------
Put the segments according to the number.
--------------------------------------------------------------------*/
void Display(int number){
byte segs = ~segments[number]; //"~" is used for common anode.
digitalWrite(segA, bitRead(segs, 0) );
digitalWrite(segB, bitRead(segs, 1) );
digitalWrite(segC, bitRead(segs, 2) );
digitalWrite(segD, bitRead(segs, 3) );
digitalWrite(segE, bitRead(segs, 4) );
digitalWrite(segF, bitRead(segs, 5) );
digitalWrite(segG, bitRead(segs, 6) );
}
again, segA or topmost is not working