 Split string into individual digits?

Hello everyone,

I have a string that I read from analogRead and did a bit of math too. It looks something like this it can range from 1.95 to 10.25. I need to write this to 3 seven segment displays. For that I chose a MAX7219 and the ledcontrol library. Now since im using only 3 of them, I get that I not only need to round the 10.25 to 10.3 or something like that. My other problem now is to split that string and display it on the seven segments.

You need to post your code.

Its still bits and pieces but here it is.

//We always have to include the library
#include "LedControl.h"
const int voltPin = 0;
float denominator;
int resistor1 = 6;
int resistor2 = 1.5;
LedControl lc=LedControl(7,6,5,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=250;

void setup() {
denominator = (float)resistor2 / (resistor1 + resistor2);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

/*
This method will scroll all the hexa-decimal
numbers and letters on the display. You will need at least
four 7-Segment digits. otherwise it won't really look that good.
*/
void scrollDigits() {
float voltage;
voltage = (voltage / 1024) * 5.0;
voltage = voltage / denominator;

lc.setDigit(0,3,i,false);
lc.setDigit(0,2,i+1,false);
lc.setDigit(0,1,i+2,false);
lc.setDigit(0,0,i+3,false);
delay(delaytime);
}
lc.clearDisplay(0);
delay(delaytime);
}

void loop() {

scrollDigits();
}
void loop() {
scrollDigits();
}

Why? Having loop(), which is called in an endless loop() do nothing more than make a function call seems silly.

float voltage;
voltage = (voltage / 1024) * 5.0;
voltage = voltage / denominator;

This could be done in one statement, with multiplication only, and no magic numbers, with a little forethought.

Store the value in an int, then, That will get you the whole number.

int wholeVoltage = voltage;

Then, subtract the whole number, multiply the rest by 100. Store the value in an int.

int fracVoltage = (voltage - wholeVoltage) * 100.0;

Then, add 5 and divide by 10.

fracVoltage += 5;
fracVoltage /=10;

If voltage was 3.262, wholeVoltage would be 3, and fracVoltage starts as 26, becomes 31, then become 3.

Right that makes sense, except that I only want to round if the voltage has 4 digits. So if the voltage is 10 or more then round. If not, then just display that number to the seven segment.

So if the voltage is 10 or more then round. If not, then just display that number to the seven segment.

Feel free to make that change.