Hello, i want to see if i can use the radios frequency link modules shown in one of the links to transmit messages from a control box into an arduino uno using the code below.
on the control box i want to use the thumbstick which is seen in the other link and is basically just two potentiometers.
can i use the transmitter to send a signal from the joystick to the arduino and therefore activate the motors and servos etc.
do i need to use two arduinos and transmitt information between them or will the single arduino work?
is this possible if so how should i go about setting this u?
A quick response would be highly appreciated as this is a school project and i need it done quickly.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <Servo.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
Servo myservo; // create servo object to control a servo
int potPinServo = 0;
int potPinDrive = 1;
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(255);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
}
void loop() {
// read value of joystich axis
int potVal = analogRead(potPinDrive);
val = analogRead(potPinServo); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(50); // waits for the servo to get there
if(potVal > 525)
{
myMotor->run(FORWARD);
myMotor->setSpeed((potVal - 512) / 2);
}
if(potVal < 500)
{
myMotor->run(BACKWARD);
myMotor->setSpeed((512 - potVal) / 2);
}
else
{
myMotor->run(RELEASE);
myMotor->setSpeed(0);
}
}