I have sketched a quick program to output 128 HEX integers "0-7E" . The problem is that I would like to have 00,01,02,.....0F etc. for the integers below 10. Here is what I am getting:
/*
Serial Call and Response in ASCII
L
*/
int talk = 0; // output int
int inByte = 0; // just a place to store input for later
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
while (talk < 127){
Serial.print(talk, HEX);
Serial.print("'");
talk = talk + 1;
}
}
}
I saw this somewhere a few days ago. I'm not sure if it was here or on a general programming forum. Give it a go.
printf in regular computers outputs to default output device, the screen. But since arduino has no default output device, it should do nothing even if it exists. You should use sprintf, which outputs to string, thus the s-printf. Just like scanf would scan from default input, the keyboard, on a regular computer, and doesn't do anything on an arduino. But if you want to recognize numbers, say from serial input, you can do sscanf, the string scanf to pick numbers from a sentence.