#define LED 13int input = 0; void setup() { pinMode(LED,OUTPUT); Serial.begin(9600); }void loop () { input = Serial.read(); if (input == '1' ) { digitalWrite(LED,HIGH); Serial.println("LED13 is ON"); } if (input == '0'){ digitalWrite(LED, LOW); Serial.println("LED13 is OFF"); }}
strings take a lot of memory from the Arduino, and I need a relatively fast processing time
However, this has a little problem: since the router is always sending serial data trought it's serial port, the LED (and other components in the future) will always answering to orders that I don't want.
Then I made a few reading and I found that the baud rate could be to high to the arduino from the router (they were the same, and at this moment I had a baudrate of 115200bps). I tought I've changed it on the router (I'm not even sure I can do that with this version of ddwrt) and on arduino to 9600bps.
A few moments of research later I found that I might need to use a string. But, according to what I've read this brings me two main problems:1- The coding. I've seen a few examples of code with string and I just don't get it!
I've read that strings take a lot of memory from the Arduino, and I need a relatively fast processing time.
I don't even know to where should I turn to!
So, the computer will send commands to the router that will transmit them to the arduino, through the serial port.
michael_x:Yes, the communication is working. If the code is simpler and I use just "a" or "b" I can control the arduino remotelly. But I need to do it using "aaaa", as described.Can you teach how to do that? I'm trying, but I can't figure it out!
#include <stdio.h>#define LED 13void setup() { pinMode(LED, OUTPUT); Serial.begin(9600);}void loop() { if (Serial.available() == 4) { char command[5]; for (int i = 0; i < 4; i++) command[i] = Serial.read(); command[4] = '\0'; Serial.println(command); if (strcmp(command, "AAAA") == 0) { digitalWrite(LED, HIGH); Serial.println("LED13 is ON"); } else if (strcmp(command, "BBBB") == 0) { digitalWrite(LED, LOW); Serial.println("LED13 is OFF"); } } else { Serial.flush(); }}