would able me fixing value 4 digits regardless of it's value? i'm using rotary encoder increment newleft sent sent via serial external device. problem needs 4 digits, ie 002f instead of 2f.
code: [select]
#include <encoder.h>
encoder knobleft(0, 1);
void setup() {
serial.begin(9600);
delay(2000);
serial.println("testing 1 encoder minimum/maximum values");
knobleft.write(513); //setting default value knobleft
}
int positionleft = -999;
void loop() {
int newleft = knobleft.read(); //read encoder
newleft = map(newleft, 0, 1000, 0, 10239); //remap input value useable range
newleft = constrain(newleft, 0, 10239); //contrain new value not report out of range values
int valleft = newleft * 100 / 10239; //convert newleft percentage lcd reporting
if (newleft != positionleft) {
serial.print("left = ");
serial.print(valleft); //print valleft lcd (future)
serial.print(" send command = ");
serial.print(newleft, hex); //send newleft value in hex external device
serial.println();
positionleft = newleft;
}
}
are asking "how defeat leading 0 suppression?" ?
the simplest way leave print routines are, , print leading zeroes yourself.
the simplest way leave print routines are, , print leading zeroes yourself.
Arduino Forum > Using Arduino > Programming Questions > fixing a value to 4 digits
arduino
Comments
Post a Comment