Point display in 4-digit 7-segment module TM1637

Hey!
I would appreciate help with the following code. I am trying to display a certain calculation on the display of the TM1637 4-digit 7-segment LED display module (not so relevant for the purpose of the calculation and what I want to display) but I am unable to put a period after the first digit on the left. I would appreciate it if you could help me put a point.

> void loop() {
> 
>   int val_div = analogRead(A1); 
>   float real_vol=val_div*0.004887;
>   float volt_bat= real_vol*1.858;
>   Serial.println("volt of battery is");
>   Serial.println(volt_bat); 
>   Serial.println(val_div); 
>   delay(1000);
> 
>   display.setBrightness(0x0f);
>   display.clear();
>   uint8_t data[] = { 0x00, 0x00, 0x00,0x00};
>   String texto = String(volt_bat); 
> 
>   data[1] = display.encodeDigit(texto[0]);
>   data[2] = display.encodeDigit(texto[2]);
>   data[3] = display.encodeDigit(texto[3]);
>  display.setSegments(data);
>  delay(1000);

Attach a picture of the result on the monitor. In the following picture, for example, I want to permanently put a dot in such a way that it looks like this: 5.30 How do I do it?

How do I do it?

Please post your complete sketch, without a > on each line please

I don't quite understand why this is necessary, but please:

#include <Arduino.h>
#include <TM1637Display.h>
#include <Servo.h>
#define CLK 5
#define DIO 6
TM1637Display display(CLK, DIO);
int pos = 0;
Servo servo1;

void setup() {

pinMode(A0,INPUT);
pinMode(A5,INPUT);
Serial.begin(9600);
servo1.attach(9);

}

void loop() {

int val_div = analogRead(A1);
float real_vol=val_div0.004887;
float volt_bat= real_vol
1.858;
Serial.println("volt of battery is");
Serial.println(volt_bat);
Serial.println(val_div);
delay(1000);

display.setBrightness(0x0f);
display.clear();
uint8_t data[] = { 0x00, 0x00, 0x00,0x00};
String texto = String(volt_bat);

data[1] = display.encodeDigit(texto[0]);
data[2] = display.encodeDigit(texto[2]);
data[3] = display.encodeDigit(texto[3]);
display.setSegments(data);
delay(1000);

int val_div2 =analogRead(A5);
float volt_operation= val_div2*0.004887;
Serial.println("volt of operation is");
Serial.println(volt_operation);
delay(30);

float current=(volt_bat-volt_operation)/99;
Serial.println("current of operation is");
Serial.println(current);
delay(30);

for (pos = 0; pos <= 180; pos += 10) {
// in steps of 1 degree
servo1.write(pos);
delay(1);
}

}

Please consult the introductory forum guidelines. The reasons are explained in detail there. You should really be at least a little familiar with the procedures.
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#code-problems

Unfortunately, there are numerous TM1637 libraries all with the same name. So please post a link to the library that you used, so we can suggest functions that might do what you ask.

Thanks for your comment.

Is that what you mean?
According to my understanding, this is the library that is installed by me..

The problem may be the display. I've had two where only the colon functioned, not the dp. So displaying time was easy, floating point not so much.
There may be a segment test option in the library you're using, if so use it - it should light all possible display segments. If the dp doesn't show with that, you're wasting your time.

There are many ways to do this. Really, this program bypasses all the useful routines that are provided by the library (which you could see by looking there). So using the library's dot control may not be intuitive.

You could either re-write the program using 'showNumberDec' which gives you control of the decimals, or you could just do something cheesy like

data[1] = display.encodeDigit(texto[0]);
data[2] = display.encodeDigit(texto[2]) | 0x80;
data[3] = display.encodeDigit(texto[3]);

Hi,
If you look in the example that comes with that library, you will find a test code.
Run that and see what displays.
It has this in it;

// Run through all the dots
	for(k=0; k <= 4; k++) {
		display.showNumberDecEx(0, (0x80 >> k), true);
		delay(TEST_DELAY);
	}

It might help, not sure how with a dedicated digital clock display.

Tom.. :smiley: :+1: :coffee: :australia:

Whenever you need to use a library, you should read the library documentation and examples.

Why do you skip 'texto[1]', or am I missing something?

textio is a string and in the string the second index - [1] is the dot.. If I display all the indexes of the string I get an incorrect display and the dot is not displayed so I had to skip it.

I checked and the screen itself is fine, so the problem is with the code and not with the screen's integrity. thanks!

Could you please show me a sample line of code that could be used as a replacement for the program I attached? In my program I am trying to display the measurement result of a real value of battery voltage with a load by connecting it to the Arduino (through an analog pin) I am interested in displaying the voltage value obtained from the measurement on the screen.

Does that mean the example code, lit up the two dots?

Tom... :smiley: :+1: :coffee: :australia:

Indeed... the 2 points are active

I think this was answered in post #6. That looks like a clock display and does not have decimal points.

Right. If you want decimal points you have to order decimal points.

1 Like

Oh, that's a separate problem. Then you have to break out the number as an integer, identify the decimal point location and then write the integer and the decimal together. I've seen ONE library that gets it right, if it encounters a DP in the print stream it will bundle it with the current digit instead of allocating a blank digit to only display a DP. But I can't remember which library. You might have to do it all manually. I assumed you have a fixed decimal point with a fixed number of digits, e.g. "0.00" to "5.00" for example. But I could be wrong. If so then there is more monkeying around to do.

Looks like it’s time to get out the black paint and brush.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.