ANALOG READ WITH 595 SEVEN SEGMENT LED DISPLAY

This basic how to visualize analog reading to seven segment display. We use seven segment 595 module.

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/ANALOG%20ON%207%20SEGMENT.zip

LED display analog

#include “Four7Seg74hc595.h”

esl::Four7Seg74hc595 display( 5,6,7 ); // SCLK, RCL, DIO pins, respectively
char sbuf[5];
uint16_t count;
uint32_t ts1, ts2;

void setup() {
Serial.begin(9600);
for (uint8_t i=0; i < 100; i++) {
display.setDigits( “—-“, 4 );
display.update();
delay(10);
}
delay(1000);
count = 0;
sprintf( sbuf, “%04u”, count );
display.setDigits( sbuf, 4 );
display.update();
ts1 = ts2 = millis();
}

uint32_t ts;

void loop() {
int sensorValue = analogRead(A0);
ts = millis();
if ( ts – ts1 >= 1000 ) {
sprintf( sbuf, “%04u”, sensorValue );

ts1 += 1000; // increment counter by 1 every 1sec
}
display.setDigits( sbuf, 4 );
display.update();
}