How can I display a corresponding analog voltage with 4 digit 7 segment display


I am reading 0 to 5V at analog input and mapping that value to 0 to 9999 [map(value,0,1023,0,9999)].

I want to display the mapped value 0 to 9999 on 4 digit 7 segment display using 74595 shift register.

Please guide me how can I write the code for this.



Use the modulo command
to break the 9999 into 4 digits.
Then you send the 4 digits to 4 shift registers.
TPIC6C595 with common anode 7-segments displays will be better than 74HC595 if you can get them.
To send the data out:
Make up a fontArray to make from bits to segments:

byte fontArray[] = {
0b00111111, // 0 1 = segment on, DP-g-f-e-d-c-b-a
0b00000110, // 1
 // 2 etc
 // 3
 // 4
 // 5
 // 6
 // 7
 // 8
0b01100111, // 9
0b00000000, //  10 blank
f      b
e      c
    d      and DP if used
Then use that mapping to send to the shift registers, I like using SPI.
13 goes to SCK
11 goes to Data on
10 goes to SRCK
MSCLR to +5
G/ to Gnd (or a PWM pin for brightness control, lower number = brighter as G/ is active longer
#include <SPI.h>
byte ssPin = 10;
fontArray from above

void setup(){
pinMode (ssPin, OUTPUT);

void loop(){
//get your number, split it into the 4 digits
// when ready to send it out:
digitalWrite(ssPin, LOW);
SPI.transfer(fontArray[digit0]); // lowest, assumes D11 goes to digit3, then Dout to Din down to digit0
digitalWrite(ssPin, HIGH); // all outputs update on this rising edge

Logic flow is a little simplified, but those sections will work.
Can get fancy and test for leading 0s and use fontArray(10) to blank them out.

if (mappedNumber < 9000){ digit3 = 10;}
if (mappedNumber < 0900){ digit2 = 10;}
if (mappedNumber < 0090){ digit1 = 10;}

before sending to the shift registers.



Thank you very much for your kind help....