Pages: [1]   Go Down
Author Topic: serial.print hex help  (Read 376 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 1
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
for ( char i=0x10; i != 0x00; i++ ) {
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it still shows 0x001; as 1
Code:
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);
  }

}
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


You are welcome.
Logged

Pages: [1]   Go Up
Jump to: