Pages: [1]   Go Down
Author Topic: HEX String to unsigned long  (Read 1200 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad


Code:
#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);
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26314
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26314
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

France
Offline Offline
Edison Member
*
Karma: 37
Posts: 1009
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello smiley

Try something liek that:
Code:
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);
« Last Edit: March 15, 2013, 05:09:49 pm by guix » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26314
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you saying you want to send the ASCII string "0x1ac"?
Or the value 0x1ac?
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Edison Member
*
Karma: 37
Posts: 1009
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

NP smiley-cool

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

Pages: [1]   Go Up
Jump to: