How would I be able to receive data like this b110110001 over serial from my laptop and turn it into its hex value? I have a serial link from my laptop to my arduino working but can only seem to send one bit I know its only down to the code I've tried putting each bit into an array but didn't seem to have much luck any help or suggestions
Code tags? I've got to go to work for a couple of hours now I'll do it as soon as I get back Thank you for your help
What are you sending from the PC?
Is it "B100010011"?
How is it terminated?
I think you can receive this!?
Then just subtract '0' from each received character and shift it into your variable:
X = (X<<1) | (C-'0')
Thank you deSilva that looks interesting so I can shift bits into x. Why do I need to subtract 'o' first? I was trying to put it into an array
this is the code I tried to modify as it works with my windows form.
int message = 0; // This will hold one byte of the serial message
int LEDPin = 13; // This is the pin that the led is conected to
int LED = 0; // The value or brightness of the LED, can be 0-255
void setup() {
Serial.begin(9600); //set serial to 9600 baud rate
}
void loop(){
if (Serial.available() > 0) { // Check to see if there is a new message
message = Serial.read(); // Put the serial input into the message
if (message == 'A'){ // If a capitol A is received
LED = 255; // Set LED to 255 (on)
digitalWrite(13, HIGH);
Serial.println("LED on"); // Send back LED on
}
if (message == 'a'){ // If a lowercase a is received
LED = 0; // Set LED to 0 (off)
digitalWrite(13, LOW);
Serial.println("LED off"); // Send back LED off
}
}
}
One question I have is what would the data look like over the serial port? I have a rainbowduino and this is what the code will end up doing is sending colour data. I know this looks like I just want someone else to do my work this isn't the case I did try myself but didn't save my attempt as it wasn't even close to working I'll try again today with this shifting bits into X and see if it works better and post my efforts for help thanks for your replies.
I can't pretend to understand what it is you're trying to ask.
BTW the LED=255 and LED = 0 lines in your example code don't do anything.
Anyway, if you're asking what 'A' and 'a' look like on the serial port
A - 01000001
a - 01100001
See ASCII (http://www.asciitable.com/)