Hello. I made e circuit of 2 temp readers print on a 4 digit 7 segment display 1 each temp .. i have cd4511 for multiplexing 1 each set of 4 digits and i cannot print the right temperatures the values from the temp in code take the right temperature but when it comes to printing 1 set is showing the temperature fine but the other shows it doubled, instead of 24c shows 48c ... And i also dont know how to print minus temperatures and the Celsius sign please help me ive tryed everything ... Also on minus temperatures the set of digits shows random numbers and not the correct minus value ...
if you check the serial monitor the Temps are correct but on the 2nd set of displays doesnt
Here is my circuit in Tinkercad: Circuit design 2 Temp reading 2 4 digit 7 segment displays | Tinkercad
The C is fixed because i couldnt find a way to be printed
i also want to print the minus sign
My Code:
int temperature;
int temperature2;
// Arduino pins connected to the 4511
const uint8_t LedA = 5;
const uint8_t LedB = 8;
const uint8_t LedC = 7;
const uint8_t LedD = 6;
const uint8_t LeA = 9;
const uint8_t LeB = 10;
const uint8_t LeC = 11;
const uint8_t LeD = 12;
// Arduino pins connected to the segment driver transistors
const uint8_t Led1 = 13;
const uint8_t Led2 = 2;
const uint8_t Led3 = 3;
const uint8_t Led4 = 4;
const uint8_t Led5 = A2;
const uint8_t Led6 = A3;
const uint8_t Led7 = A4;
const uint8_t Led8 = A5;
void setup()
{
// Let the Arduino know which pins go where
pinMode(LedA, OUTPUT);
pinMode(LedB, OUTPUT);
pinMode(LedC, OUTPUT);
pinMode(LedD, OUTPUT);
pinMode(LeA, OUTPUT);
pinMode(LeB, OUTPUT);
pinMode(LeC, OUTPUT);
pinMode(LeD, OUTPUT);
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
pinMode(Led4, OUTPUT);
pinMode(Led5, OUTPUT);
pinMode(Led6, OUTPUT);
pinMode(Led7, OUTPUT);
pinMode(Led8, OUTPUT);
digitalWrite(Led1, LOW);
digitalWrite(Led2, LOW);
digitalWrite(Led3, LOW);
digitalWrite(Led4, LOW);
digitalWrite(Led5, LOW);
digitalWrite(Led6, LOW);
digitalWrite(Led7, LOW);
digitalWrite(Led8, LOW);
Serial.begin(9600);
}
void loop()
{
temperature = -40 + 0.488155 * (analogRead(A0) - 20);
temperature2 = -40 + 0.488155 * (analogRead(A1) - 20);
print_number(temperature);
print_number2(temperature2);
Serial.print ("IN ");
Serial.print(temperature);
Serial.println(" C");
Serial.print ("OUT ");
Serial.print(temperature2);
Serial.println(" C");
}
void print_number(unsigned i) {
static int l = 2;
set_digit(Led3, l, i/10 );
set_digit(Led2, l, i/1 );
}
void print_number2(unsigned n) {
static int d = 1;
set_digit2(Led7, d, n/10 );
set_digit2(Led6, d, n/1 );
}
void set_digit(const uint8_t sec, const unsigned l, const unsigned value) {
set_number(value);
digitalWrite(sec, HIGH);
delay(l);
digitalWrite(sec, LOW);
}
void set_digit2(const uint8_t led, const unsigned d, const unsigned value2) {
set_number2(value2);
digitalWrite(led, HIGH);
delay(d);
digitalWrite(led, LOW);
}
void set_number(const unsigned i) {
static const struct number {
uint8_t d;
uint8_t c;
uint8_t b;
uint8_t a;
} numbers[] = {
{ LOW, LOW, LOW, LOW}, /* 0 */
{ LOW, LOW, LOW, HIGH}, /* 1 */
{ LOW, LOW, HIGH, LOW}, /* 2 */
{ LOW, LOW, HIGH, HIGH}, /* 3 */
{ LOW, HIGH, LOW, LOW}, /* 4 */
{ LOW, HIGH, LOW, HIGH}, /* 5 */
{ LOW, HIGH, HIGH, LOW}, /* 6 */
{ LOW, HIGH, HIGH, HIGH}, /* 7 */
{HIGH, LOW, LOW, LOW}, /* 8 */
{HIGH, LOW, LOW, HIGH}, /* 9 */
};
digitalWrite(LedA, numbers[i%10].a);
digitalWrite(LedB, numbers[i%10].b);
digitalWrite(LedC, numbers[i%10].c);
digitalWrite(LedD, numbers[i%10].d);
}
void set_number2(const unsigned n) {
static const struct number {
uint8_t d;
uint8_t c;
uint8_t b;
uint8_t a;
} numbers[] = {
{ LOW, LOW, LOW, LOW}, /* 0 */
{ LOW, LOW, LOW, HIGH}, /* 1 */
{ LOW, LOW, HIGH, LOW}, /* 2 */
{ LOW, LOW, HIGH, HIGH}, /* 3 */
{ LOW, HIGH, LOW, LOW}, /* 4 */
{ LOW, HIGH, LOW, HIGH}, /* 5 */
{ LOW, HIGH, HIGH, LOW}, /* 6 */
{ LOW, HIGH, HIGH, HIGH}, /* 7 */
{HIGH, LOW, LOW, LOW}, /* 8 */
{HIGH, LOW, LOW, HIGH}, /* 9 */
};
digitalWrite(LeA, numbers[n%10].a);
digitalWrite(LeB, numbers[n%10].b);
digitalWrite(LeC, numbers[n%10].c);
digitalWrite(LeD, numbers[n%10].d);
}
Thank you in advance
Banned_L