So I have a 4 digit display, it is four 7 segment displays controlled via a tm1637.
I have a sonar spitting out inches, but (with a lot of help from users here) got it to format it into Feet and Inches.
So this ends up with a variable that is 4 digits long.
// UKHeliBob's math to work out Feet and Inches seperatly
int feet = inches / 12 ; //divides inches by 12, discards any remainder and puts the result in the feet variable (integer division)
inches %= 12 ; //divides inches by 12 and puts the remainder in the inches variable (modulo operator)
// Format Feet and Inches from above into a buffer variable, then print via serial.
//int buffer;
char buffer[4];
sprintf (buffer, "%02d%02d", feet, inches);
Serial.println (buffer);
//Display code from example
distance = buffer; /* read the value from the sensor */
memset(bits, 0, 4); /* reset array when we use it */
for(int i = 3; i >= 0; i--) {
/* get single bits of the analog value */
bits[i] = distance % 10;
distance = distance / 10;
tm1637.display(i, bits[i]); /* display by 4-digital display */
}
delay(100);
}
The problem is, while it prints fine in the serial output, the display only shows "2286".
No matter what the sonar is reporting or what is shown on the serial output.
You can NOT fit 4 digits and a NULL in a 4 element array.
distance = buffer; /* read the value from the sensor */
WTF is this supposed to do?
So "char buffer[5];" ?
The LCD code use to take the long variable from the sonar before so they had that line to make it easier on the eyes.
I kept it in as the code uses the variable 3 times so I can change the bit after the = to make a mass change.
If that makes sense?
It does not, since the code snippet you posted does not have all the data types specified. Even if buffer and distance are the same type, that is NOT how to copy the contents from one array to another.
PaulS:
Yes. I prefer even sizes, but odd works, too.
It does not, since the code snippet you posted does not have all the data types specified. Even if buffer and distance are the same type, that is NOT how to copy the contents from one array to another.
I really don't understand any of this
I just don't get how to put the output of that "buffer" into this display..
C:\Users\Jack\AppData\Local\Temp\ccUctUMZ.ltrans0.ltrans.o: In function `setup':
C:\Users\Jack\Documents\Arduino\sketch_jan01a/sketch_jan01a.ino:16: undefined reference to `TM1637Display::setBrightness(unsigned char, bool)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.