Hi,
I used LCD to display the float data types that includes decimals for all analog sensors, but for a specific application i wanted to display the sensor data on a 4 digit 7 segment led display.
My experimentation began with using 2 shift registers (74HC595) using one of them to drive the segments of the Led Display & other switching the digits of the 7 segment display. I wrote the code & it works for 'int' data type where there is NO decimal involved. Here is the code
/*Program to display data on a 2 digit Common Anode 7 segment LED Display using 2 74HC595 Shift Registors.
Written By
Shiharan Choudhury
utomate With Arduino
*/
int clockPin = 8; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock)
int latchPin = 9; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch)
int dataPin = 10; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)
int SensorPin = A0; // Pin A0 of Arduino connected to the data pin of analog sensor
int UnitData; //Data to be displayed on the unit place
int TenData; //Data to be displayed on the ten'th place
int Parameter; // The parameter to measure using sensor
int SensorDataValue; // Variable to store sensor data value
//Digits Matrix - 0 a 9
byte numbers[] = {
B01111110, // Zero
B00110000, // One
B01101101, // Two
B01111001, // Three
B00110011, // Four
B01011011, // Five
B01011111, // Six
B01110000, // Seven
B01111111, // Eight
B01111011, // Nine
};
void setup() {
pinMode(latchPin, OUTPUT); // Declaring the PIN 8 of the arduino as Output
pinMode(clockPin, OUTPUT); // Declaring the PIN 9 of the arduino as Output
pinMode(dataPin, OUTPUT); // Declaring the PIN 10 of the arduino as Output
pinMode(SensorPin, INPUT); // Declaring the PIN 2 of the arduino as input
Serial.begin(9600); // begin serial communication at 9600baud rate
}
void loop() {
// This is where we will make all the calculations of the sensor data including ADC
Parameter = analogRead(A0); // Reading the sensor data
SensorDataValue = Parameter*0.00488758; // Converting sensor data into digital equivalent by multiplying 5/1023
UnitData = SensorDataValue % 10;
TenData = SensorDataValue / 10;
// Here we set the approperiate display & coresponding data to send from the arduino to the 7 segment LED display.
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8 ); //Set Digit 1 (top view from left to right)
shiftOut(dataPin, clockPin, LSBFIRST, ~numbers[TenData]); //Set the SensorDataValue (TenData)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set Digit 2
shiftOut(dataPin, clockPin, LSBFIRST, ~numbers[UnitData]); //Set the SensorDataValue (UnitData)
digitalWrite(latchPin, HIGH);
Serial.println(SensorDataValue); // print the light on serial monitor
delay(750);
}
Here the sensor data is displayed as a number ranging from 0-99 but i would like to display accurate data with decimal places using float data type on the 7 segment LED display. I would appreciate if someone educates me about the process where i can display decimal values on the display such as 0.18/1.95/2.87/99.91 etc etc