I am trying ... with minimal success to change/Check and also run voids through the serial monitor .the code i put i am having probles is that when i am try to send a value larger than 9 the value assigns a diffrent number Ex i set to 200 but arduino sets it as 512.. i got around it deviding the value by 1.6 and got me the new number and only works upto 90 , but i am tryn to see how it should be done correctly...
const uint16_t inputLength = 512;
int ss = 0;
int bHold = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if ( Serial.available() > 0 )
{
static char input[inputLength];
static uint16_t i;
char c = Serial.read();
if ( c != '\r' && c != '\n' && i < inputLength - 1)
input[i++] = c;
else
{
input[i] = '0円';
i = 0;
uint16_t array[80];
uint16_t j = 0;
if ( !strncmp(input, "ss", 2) )
{
char* p = input + 2;
while ( (p = strchr(p, ' ')) != NULL )
array[j++] = strtol(p, &p, 10); //< changed from 16
for ( uint8_t i = 0; i < j; i++ )
{
ss = array[i];
Serial.println(ss);
}
}
if ( !strncmp(input, "bHold", 5) )
{
char* p = input + 5;
while ( (p = strchr(p, ' ')) != NULL )
array[j++] = strtol(p, &p, 10); //< changed from 16
for ( uint8_t i = 0; i < j; i++ )
{
bHold = array[i];
// bHold=bHold /1.6;
Serial.println(bHold);
}
}
if ( !strncmp(input, "Whos There", 10) )
{
Serial.print("me");
}
if ( !strncmp(input, "hello", 5) )
{
Serial.print("hi");
}
if ( !strncmp(input, "sa", 2) )
{
Serial.print(" ss= ");
Serial.print(ss);
Serial.print(" bHold= ");
Serial.print(bHold);
Serial.println(" ");
Serial.println("==============================");
}
}
}
}
Thank you for any tips you can give...
EDIT: I am trying to pass a new value with command on the serial monitor "ss 500"..so that in the arsuino ss = 500. but in this case it makes it equal to 1280.
EDIT2: Chaged the strol to 10...works perfectly ...Thank you TisteAndii!!!!
-
What do you mean with "ss = array[i], DEC;". That is "ss=DEC" and gives the same value ss. Should be "ss = array[i]; Serial.println(ss, DEC);"Mikael Patel– Mikael Patel2016年02月04日 06:40:17 +00:00Commented Feb 4, 2016 at 6:40
-
Edit the code in your post if you have made any changes to it so far.SoreDakeNoKoto– SoreDakeNoKoto2016年02月04日 08:43:23 +00:00Commented Feb 4, 2016 at 8:43
1 Answer 1
You are setting the input string's base to 16 instead of 10 in your strtol
conversions, which is why you are getting 1280 when you expect 500.
-
Ex i set to 200 but arduino sets it as 512
- TisteAndii is right. 0x200 is 512 in decimal.2016年02月04日 10:22:09 +00:00Commented Feb 4, 2016 at 10:22