Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Los Electrofaster
Published © GPL3+

Potentiometer value using a 4 digit 7 segments display

A simple way to present the value of a potentiometer using a 4-digit 7-segment display without getting complicated in the attempt.

BeginnerFull instructions provided1 hour4,621
Potentiometer value using a 4 digit 7 segments display

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
TM1637 4-Digit 7-Segment Display Module
×1
Jumper wires (generic)
Jumper wires (generic)
×7
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Potentiometer value 4-digit 7-segments display

Code

Potentiometer to 4-digit 7-segments display

Arduino
Reads the value of the potentiometer and presents it on the 4-digit 7-segments display
#include <Arduino.h>
#include <TM1637Display.h> 
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);

void setup() {

}

void loop() {
  display.setBrightness(0x0f);
  display.clear();
  uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };
  int value = analogRead(A0); // read of potentiometer value
  String texto = String(value); 
  if (value > 999){
    data[0] = display.encodeDigit(texto[0]);
    data[1] = display.encodeDigit(texto[1]);
    data[2] = display.encodeDigit(texto[2]);
    data[3] = display.encodeDigit(texto[3]);
  } else if (value > 99){
    data[1] = display.encodeDigit(texto[0]);
    data[2] = display.encodeDigit(texto[1]);
    data[3] = display.encodeDigit(texto[2]);
  } else if (value > 9){
    data[2] = display.encodeDigit(texto[0]);
    data[3] = display.encodeDigit(texto[1]);
  } else {
    data[3] = display.encodeDigit(texto[0]);
  }
  display.setSegments(data);

  delay(100);
}

Credits

Los Electrofaster
8 projects • 7 followers
Thanks to Avishay.

Comments