I wasn't sure where else this topic belonged.
Hello,
For a school project of mine, I'm trying to get the Arduino board (mounted on a robot body) to be able to react to keyboard presses. However, after searching through Google, the arduino website, and this board, I haven't been able to figure out how to accomplish this and I have no idea where to start (if I've missed it, I apologize). I'm trying to control servos based on the arrow keys (or WASD if that's easier). Is this possible?
For an idea of what I'm trying to do:
int ledPinNorth = 1;
int ledPinSouth = 2;
int ledPinWest = 3;
int ledPinEast = 4;
int ledSelect = 1;
void setup()
{
pinMode(ledPinNorth, OUTPUT);
pinMode(ledPinSouth, OUTPUT);
pinMode(ledPinWest, OUTPUT);
pinMode(ledPinEast, OUTPUT);
}
void loop()
{
if (ledSelect = 1) //This would make the robot travel north.
{
digitalWrite(ledPinNorth, HIGH);
digitalWrite(ledPinSouth, LOW);
digitalWrite(ledPinWest, LOW);
digitalWrite(ledPinEast, LOW);
}
else if (ledSelect = 2) //south
{
digitalWrite(ledPinNorth, LOW);
digitalWrite(ledPinSouth, HIGH);
digitalWrite(ledPinWest, LOW);
digitalWrite(ledPinEast, LOW);
}
else if (ledSelect = 3) //west
{
digitalWrite(ledPinNorth, LOW);
digitalWrite(ledPinSouth, LOW);
digitalWrite(ledPinWest, HIGH);
digitalWrite(ledPinEast, LOW);
}
else if (ledSelect = 4) //and east
{
digitalWrite(ledPinNorth, LOW);
digitalWrite(ledPinSouth, LOW);
digitalWrite(ledPinWest, LOW);
digitalWrite(ledPinEast, HIGH);
}
else
{
delay(10);
}
}
To give an example controlling LEDs instead of servos. I want to be able to control the LEDs with the keyboard instead of the ledSelect variable.
Thanks in advance.
edit: "digitialWrite", ha. Fixed for spelling.