system
July 6, 2013, 6:54pm
#1
I want to send "11111111"by input this to the serial using this code:
#include <VirtualWire.h>
char buf1[8];
int i;
void setup() {
Serial.begin(9600);
vw_set_tx_pin(3);
vw_set_rx_pin(2);
vw_setup(2000);
vw_rx_start();
}
void loop() {
while (Serial.available() > 0) {
int x = Serial.parseInt();
Serial.println(x);
for(i=7;i>=0;i--){
buf1[i]= x % 10;
x /= 10;
}
vw_send((uint8_t *)buf1, strlen(buf1));
}
}
This code work for example “11111” but for not work for “11111111”.
LarryD
July 6, 2013, 7:36pm
#2
Look up strlen.
A string is a NULL terminated array.
Edit:
not work for "11111111"
char buf1[8];
system
July 7, 2013, 12:02am
#3
I change buf1[8] to buf1[9] and the same error.Who i solve this?
LarryD
July 7, 2013, 12:44am
#4
Hint:
11111 works
Integer -32768 to 32767
int x = Serial.parseInt();
system
July 7, 2013, 12:54am
#5
I dont understand,can you explain?
LarryD
July 7, 2013, 1:04am
#6
11111 is in this range -32768 to 32767
111111 or 1111111 or 11111111 are not integers they are bigger than 32767
int x = Serial.parseInt(); // Returns an integer, your 11111111 is too big
system
July 7, 2013, 1:14am
#7
I understand.Is any way to solve this?
Arrch
July 7, 2013, 1:38am
#8
vasr:
I understand.Is any way to solve this?
You're receiving it through Serial as a string, stuffing it into an int, and using the int to convert it to BCD. Why not just subtracted '0' from each character when you receive it and put it in the array. When you receive a non-number send the array.
Arrch
July 7, 2013, 3:01am
#10
vasr:
Can you make a example?
char a = Serial.read();
if (isDigit(a))
{
b[i] = a - '0';
i++;
}
else
{
// send the data
}
system
July 7, 2013, 11:51am
#11
Still not working, any ideia?
system
July 7, 2013, 12:45pm
#12
Still not working, any ideia?
Hey, I've got an idea. Why don't you POST SOME CODE?
While you're at it, feel free to volunteer just what the hell "Still not working" means!