So I need to get a string from my pc to arduino, it's terminated by an '\n'. (its a 27bit binary number)
but for some reason after 5 digits it will give negative numbers, here's code
kamhagh:
So I need to get a string from my pc to arduino, it's terminated by an '\n'. (its a 27bit binary number)
For example when i send number 0x700FF0F\n to my arduino it will see 7 0 0 f f 0 f \ n (not 7 0 0 f f 0 f \n)
If your description is correct, then it is the sender's fault, not the receiver's fault.
But, since you did not post your actual code, it may well be that your receiver code is not what you think it is either.
arduinodlb:
If your description is correct, then it is the sender's fault, not the receiver's fault.
But, since you did not post your actual code, it may well be that your receiver code is not what you think it is either.
yeah it's weird it's arduino's consoles fault, other serial apps work fine, but as i have a new problem i changed the subject and tittle! wow that was a quick answer
arduinodlb:
Woooh. You just went back and changed the description of the problem, he title in the original message, and the code to something different.
Don't do that.
It means the comments after it make no sense for others reading later. Just add a new message down the bottom with your updated code/information.
:o sorry, i didn't expect a reply this quickly! I don't have the old message anymore!
kamhagh:
So I need to get a string from my pc to arduino, it's terminated by an '\n'. (its a 27bit binary number)
but for some reason after 5 digits it will give negative numbers, here's code
int is 16 bit in Arduino (-32,768 to 32,767).
String.toInt() returns a long. Change your return to long for 32 bits.
void loop() {
if(Serial.available() > 0) {
/*
you will need to write your own way of receiving input and determining when to loop in here...
I am just including the part that sets the color picked above.
pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
*/
long hexval= PC_Receive(); // You sent: 0x01FF8C3C or, integer value,33524796
Serial.println(hexval, HEX);
if(hexval = 251658240) {
clearLEDs();
leds.show();
}
int led=hexval >> 24;
int r = hexval >> 16 & 0xFF;
int g = hexval >> 8 & 0xFF;
int b = hexval & 0xFF;
Serial.print("Led: ");
Serial.println(led, HEX);
Serial.print("R: ");
Serial.println(r);
Serial.print("B: ");
Serial.println(b);
Serial.print("G: ");
Serial.println(g);
leds.setPixelColor(led,r,g,b); //LED 1 as color FF8C3C
leds.show();
// delay(500);
}
for some reason my LED is always F and rbg are all 0, i guess it has to do something with the value types, but i don’t see why, as result is less then 16 bytes (8 bytes)