I am trying to control a motor wirelessly through XBee Proto Shields. The motor is controlled via an adafruit motor shield with one XBee ProtoShield stacked on top. WHat I am trying to do is, to send a signal from one protomshield connected to the computer to the one stacked on the motorshield to control it. The idea is to type '1' and that should start the motor.
The coordinator code is:
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Input 1 to move left, 2 to move right, 3 to move forward and 4 to move backwards");
}
void loop() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 1)
{
Serial.println("1");
}
}}
The end device code is:`
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
int sentData;
void setup()
{
Serial.begin (9600);
AFMS.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
sentData=Serial.read();
if(sentData=='1'){
myMotor2->setSpeed(250);
myMotor2->run(FORWARD);
}
}
}