Go Down

Topic: serial.print hex help (Read 419 times) previous topic - next topic

michael040990

hello all i had this figured out at one time but i cant seem to find it but i have this small peace of code
Code: [Select]

for(char i=0x010;i>=0x0FF;i++){
Send_DIRECT_CODE_To_Sony(i);  //End Tv Send Code
Serial.println(i);
delay(delay_time);
}


basically i want to start at 0x010 and end at 0x0FF
and display the full hex value in the serial console i has to = something like 0x010 no 10 that is what is saying now
that way it sends the hex code to the rest of the code but that part isnt important lets get serial write to work first

Coding Badly

Code: [Select]
for ( char i=0x10; i != 0x00; i++ ) {

michael040990

it still shows 0x001; as 1
Code: [Select]
void setup() {
 int delay_time = 100;
 Serial.begin(9600);
// ch(5,8);      //this process takes atleast 600 miliseconds
 Serial.println("starting");
 //delay(delay_time);
for (char i=0x000; i != 0xFFF; i++ ) {
   //Send_DIRECT_CODE_To_Sony(i);
   Serial.println(i,HEX);
   delay(delay_time);
 }

}

Coding Badly

Quote
for (char i=0x000; i != 0xFFF; i++ ) {


Two problems...

1. That is not the code I posted.

2. 0xFFF exceeds the range of char in a way that the comparison is always true.

michael040990

thank you for your help i just added your code to mine and filled in the values i got it working were the rest of the program reads the hex values and i learned that you can use != instead of <= in this case and thats pretty cool thanks for all your help

Coding Badly


Go Up