#include AFMotor.h
#include Arduino.h
#include Servo.h
Servo servo;
int position = 90;
int newPosition;
AF_DCMotor dcMotor1(1); // This defines the name of the motor (dcMotor1) and port number (1).
AF_DCMotor dcMotor2(2);
void setup() {
servo.attach(10);
dcMotor1.setSpeed(200); // Set the speed for the selected DC motor. Values can range between 0 and 255.
dcMotor2.setSpeed(200);
}
void loop() {
delay(2000); //forward
dcMotor1.run(FORWARD);
dcMotor2.run(FORWARD);
delay(8400);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(500);
dcMotor1.run(FORWARD); //turn
dcMotor2.run(BACKWARD);
delay(700);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(500);
dcMotor1.run(FORWARD); //forward
dcMotor2.run(FORWARD);
delay(8400);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(5000000000);
dcMotor1.run(FORWARD); //turn
dcMotor2.run(BACKWARD);
delay(690);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(500);
dcMotor1.run(FORWARD); //forward
dcMotor2.run(FORWARD);
delay(8400);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(500);
dcMotor1.run(FORWARD); //turn
dcMotor2.run(BACKWARD);
delay(690);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(500);
dcMotor1.run(FORWARD); //forward
dcMotor2.run(FORWARD);
delay(8650);
dcMotor1.run(RELEASE);
dcMotor2.run(RELEASE);
delay(500);
servo.write(180); //dump load
delay(5000);
servo.write(position);
delay(10000000);
}
#include RH_ASK.h
#include AFMotor.h
#include Arduino.h
RH_ASK driver;
AF_DCMotor dcMotor2(2);
void setup()
{
Serial.begin(9600);
if (!driver.init())
{
Serial.println("init failed");
}
dcMotor2.setSpeed(200);
}
void loop()
{
delay(5000);
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // read distance received
{
String message = "";
for (int i = 0; i < buflen; i++)
{
message += (char)buf[i];
}
message.trim();
int number = message.substring(1).toInt();
float duration = number * 870 ;
Serial.print(number); //print distance received
dcMotor2.run(FORWARD); // drive forward for duration calculated
delay(duration);
dcMotor2.run(RELEASE);
delay(10000000000); // end
}
}