Hey all!
Can someone explain me how to convert a int to uint8_t ?
I´am trying to send the A0-A5 ports to a other arduino via RFM22 but the rfm22.send() command needs a uint8_t input and i get a int from analogRead()
Greetings
Daniel
Playing with RFM22 lib
Re: Playing with RFM22 lib
the_char = ((char) (the_int/4))
send the_char
or
the_char1 = (((char) the_int & 0xff00)>>4)
the_char2 = ((char) the_int & 0x00ff)
send the_char1
send the_char2
send the_char
or
the_char1 = (((char) the_int & 0xff00)>>4)
the_char2 = ((char) the_int & 0x00ff)
send the_char1
send the_char2
Re: Playing with RFM22 lib
Hmm, tried some stuff but i cant get it working
Currently it looks like
the error is
Currently it looks like
Code: Select all
//uint8_t data[] = "Hello World!"; //<- this is the original what is working
uint8_t data[4] = (((char) analogRead(A0) & 0xff00)>>4); //<- dont work :-(
rf22.send(data, sizeof(data));
the error is
Code: Select all
error: array must be initialized with a brace-enclosed initializer
Re: Playing with RFM22 lib
a simple explanation:
uint8_t data[4];
uint16_t analog_data;
analog_data = analogRead(A0) ;
data[0] = analog_data
data[1] = analog_data>>8&0xff;
analog_data = analogRead(A0) ;
data[2] = analog_data
data[3] = analog_data>>8&0xff;
rf22.send(data, sizeof(data));
uint8_t data[4];
uint16_t analog_data;
analog_data = analogRead(A0) ;
data[0] = analog_data
data[1] = analog_data>>8&0xff;
analog_data = analogRead(A0) ;
data[2] = analog_data
data[3] = analog_data>>8&0xff;
rf22.send(data, sizeof(data));
Re: Playing with RFM22 lib
your question was: Can someone explain me how to convert a int to uint8_t ?
uint8_t data;
data = ((char) (analogRead(A0)/4));
rf22.send(data, data);
uint8_t data;
data = ((char) (analogRead(A0)/4));
rf22.send(data, data);
Re: Playing with RFM22 lib
thanks got it working with this:
Code: Select all
int ADC0 = analogRead(A0);
rf22.send((uint8_t*)&ADC0, sizeof(ADC0));