TGIF or maybe not

So I totally bombed my thermodynamics midterm tonight. I froze. That’s about it. I drown my sorrows with Big Macs and the works. After a bit of TV and adult beverages I cracked open the IDE and started working with the coding of the transceivers again. Initially I thought I would be limited by the type of data I could pass through with the HopeRF Library. It turns out that what I was dealing with was simply something not often done with arduino (due to its target audience being people who are often just starting with programming) but fairly common in C++. I had to fumble with the concept for a while. It was not easy to wrap my head around points and unsigned integers. In fact, it’s still pretty hazy.



In the end I finally found the way with the function atoi() which converted a const char* to an int. My test code for the transceivers are included below. It’s a simple modification of the sample Client sketch that came with the library.

#include
// Declare the HRFMessage to use Serial for IO with the HM-TR module
HRFMessage client(&Serial);
long lastSendTime = 0;
int msg;
void setup()
{
Serial.begin(9600);
pinMode(2,OUTPUT);
digitalWrite(2, LOW);
pinMode(3,OUTPUT);
digitalWrite(3, HIGH);
pinMode(4,OUTPUT);
}
void loop()
{
// But always look for a reply
uint8_t buf[HRF_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (client.recv((uint8_t*)&buf, &len))
{
msg = atoi((const char*)buf);
}
switch(msg)
{
case 11:
digitalWrite(4, HIGH);
break;
case 22:
digitalWrite(4, LOW);
break;
}
msg =0;
}



One Comment Add yours

  1. Craig says:

    Midterms come and go… solid transceiver code is for life!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s