Go Down

Topic: Converting byte to nibbles (Read 1 time) previous topic - next topic


Hello. I need help converting 1 byte into 2 nibbles and print them. I tried this but it doesn't work.

Code: [Select]
const int analogInPin0 = A0;
int readByte = 0;
int mappedByte = 0;
int bottom_nibble  = 0;
int top_nibble = 0;

void setup() {
  // initialize serial communications at 115200 bps:

void loop() {
   readByte = analogRead(analogInPin0);           
   mappedByte = map(readByte, 0, 1023, 0, 255);
   bottom_nibble = readByte & 0xf;
   top_nibble = ( readByte > 4 ) & 0xf;



I. Think you need the shift operator >> not the greater than operator >


Code: [Select]
   mappedByte = map(readByte, 0, 1023, 0, 255);
That's an expensive way to divide by 4.
The art of getting good answers lies in asking good questions.


I thought that but then.. I heard a voice-over (it sounded like HAL9000) that was all "don't make it so easy for the guy" . Regards

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131