Go Down

Topic: HEX String to unsigned long (Read 1 time) previous topic - next topic

Xenon69

I need to send hex string by IR but at firs i need to combine it from 3 variables. So i use string function to merge HEX (1+A+C= 1AC) but problem is that i can't to send string -----> irsend.sendSony(string, 12);  IRSend library need to send unsigned long or int. So then i need to convert string to unsigned long code but i don't know how :(


Code: [Select]

#include <IRremote.h>

IRsend irsend;

String stringOne;
String stringTwo;
String stringThree;
String string;

unsigned long code;

void setup()
{
  Serial.begin(9600);
}


void loop() {
 
  int Team = 1;     //in HEX = 1
  int Player = 10;  //in HEX = A
  int Weapon = 12;  //in HEX = C
 
  stringOne =  String(Team, HEX);     //HEX = 1
  stringTwo =  String(Player, HEX);   //HEX = A
  stringThree =  String(Weapon, HEX); //HEX = C

  string =  String(stringOne + stringTwo + stringThree); //1 + A + C = 1AC
  Serial.println(string); // i get 1AC
 
  //need convert it like this to send it, but i can't
  code = string; //????????????
 
  //Because "irsend.sendSony" accept just (unsigned long or int) i can't send string directly   
  irsend.sendSony(code, 12); // need to send it like this irsend.sendSony(0x1AC, 12);
  delay(25);
}

AWOL

Hex is just a convenient way of presenting binary to humans, but hex, decimal, octal or binary, it's all the same value to the processor.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Xenon69

ok, now i understand about HEX, OCTAL, DEC ... but how i can string convert to unsigned long to make IR library understand that i wand send 0x1AC code?

AWOL

Tell me why you made a String (note, that's not the same as a string) when all you want to do is transmit a binary value.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Xenon69

i just want 3 different hex values stick together and send as one code and in receiver i was split them again and asign to variables

TRANSMITTER
variable1 = 1;   //hex 1
variable2 = 10; //hex A
variable3 = 12; //hex C

i want stick them together and send as

0x1AC



RECEIVER

receive = 1AC

split this received code and asign to variable:
variable1 = 1;  // hex 1
variable2 = 10; // hex A
variable3 = 12; // hex C

guix

#5
Mar 15, 2013, 11:07 pm Last Edit: Mar 15, 2013, 11:09 pm by guix Reason: 1
Hello :)

Try something liek that:
Code: [Select]

int Team = 1;     //in HEX = 1
int Player = 10;  //in HEX = A
int Weapon = 12;  //in HEX = C

irsend.sendSony( Team << 8 | Player << 4 | Weapon , 12);

AWOL

Are you saying you want to send the ASCII string "0x1ac"?
Or the value 0x1ac?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Xenon69

Perfect!!! Thank you "guix" !!
That is that what i want! Looks so easy but i never would do this without your help!

guix

NP 8)

And if you are wondering how to "decode", here is a little example: http://codepad.org/kCuH0UVW

Go Up