welcome everybody
i need help
i have:
Arduino Mega 2560
hx711
3-digit, 7-segment display
Now I have the weight code, which is as follows
#include "HX711.h"
#define DOUT 32
#define CLK 30
HX711 scale;
float calibration_factor = -100000; //Change this for calibration your load cell
void setup() {
Serial.begin(9600);
scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); //Reset the scale to 0
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print(abs(scale.get_units())*100,0);
Serial.println();
}
The weight is displayed on the serial screen
I have the code for the screen, which is the following
int time = 5;
int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int DIG1 = 10;
int DIG2 = 11;
int DIG3 = 12;
void choose_digit(char num) {
switch(num) {
default:
// 0 default value
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;
case 1:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 2:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
break;
case 3:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
break;
case 4:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 5:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 6:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 7:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 8:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 9:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
}
}
void pick_digit(int digit){
digitalWrite(DIG1, HIGH);
digitalWrite(DIG2, HIGH);
digitalWrite(DIG3, HIGH);
switch(digit){
case 1: digitalWrite(DIG1, LOW);break;
case 2: digitalWrite(DIG2, LOW);break;
default: digitalWrite(DIG3, LOW);break;
}
}
void seven_segment(int number){
unsigned char hundreds = int (number/100);
unsigned char tens = int ((number/10)%10);
unsigned char ones = int (number%10);
//123
choose_digit(hundreds);
pick_digit(1);
delay(time);
choose_digit(tens);
pick_digit(2);
delay(time);
choose_digit(ones);
pick_digit(3);
delay(time);
}
///////////////////
///////////////////
void setup() {
pinMode(DIG1, OUTPUT);
pinMode(DIG2, OUTPUT);
pinMode(DIG3, OUTPUT);
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
Serial.begin(9600);
//////////////////
//////////////////
}
void loop() {
int sensor_value = A0;
Serial.println(sensor_value);
seven_segment(sensor_value);
delay(1);
//////////////////
//////////////////
}
The number appears on the screen according to the value of A0
Please help with the following code:
I want to display the weight value on a 3-digit 7-segment display
Because my max weight is 280kg
Can you help me?
thank you all