I've been working on a "robot" of sorts that is mobilized by two continuous rotation servos, which is controlled via my Arduino Uno R3.
Currently I drive the bot around by sending commands to the Arduino from the serial comm. terminal in the Arduino IDE, works fine, but is a bit annoying to control having to send one command at a time.
I understand Serial communication is asynchronous and can only do one bit at a time... But are there any tricks someone can point me towards where I can make it a bit more "real-time"?
i.e. -- I press the up-arrow key and while the key is being pressed the bot goes forward, as soon as I release the key the bot stops.
I do plan on making a stand alone controller down the road and I realize that'll make my life a lot easier, but in the interest of time, I have no other choice than to rely on serial comm. to control my bot (school project with a due date).
Currently I have my two servos driven by a power circuit I built, which the Arduino uses as an interface to the servos (power board feeds servos 6V, Arduino operates servos via signal line to servos).
My code is currently just a switch statement which decides which action to take depending on key pressed, following is a portion of my code:
----------------------------Start code------------------------------------------------
#include <Servo.h>
Servo servoL;
Servo servoR;
int inByte;
void setup()
{
Serial.begin(9600);
servoL.attach (5);
servoR.attach (6);
}
void loop()
{
if(Serial.available() > 0)
{
inByte = Serial.read();
control();
}
}
void control()
{
switch(inByte)
{
case 'a':
servoLeft();
break;
----------------------Continued---------------------------
void servoLeft()
{
servoR.write(99);
servoL.write(120);
return;
}
-----------------------------------End code--------------------------------
Obviously I only included the parts of interest, but is there anyway to make the servo respond upon a closed key? I tried looking up how to stream data to Arduino but could not figure out how to make it work for my purposes, obviously I'm still learning here...
Thanks for any help, it is greatly appreciated!
-jay
P.S. -
Sorry if this is in the wrong section, wasn't sure if it should go in the motor section or this one, but I figured it was mainly a programming issue...