Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <Wire.h>
- #include <Adafruit_MotorShield.h>
- #include "utility/Adafruit_MS_PWMServoDriver.h"
- Adafruit_MotorShield AFMS = Adafruit_MotorShield();
- Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
- Servo myservo;
- int FWD = 0;
- int BCK = 0;
- int RGT = 0;
- int LFT = 0;
- void setup() {
- AFMS.begin(); // create with the default frequency 1.6KHz
- myMotor->setSpeed(0);
- myMotor->run(RELEASE);
- myservo.attach(10); // attaches the servo on pin 10 to the servo object
- pinMode(4, INPUT);
- pinMode(5, INPUT);
- pinMode(6, INPUT);
- pinMode(7, INPUT);
- Serial.begin(9600);
- }
- int maxspeed = 100;
- /*
- myMotor->run(RELEASE);
- myservo.write(90);
- */
- void loop() {
- FWD = digitalRead(4);
- BCK = digitalRead(5);
- LFT = digitalRead(6);
- RGT = digitalRead(7);
- // ------ Forward routine ------
- if (FWD == 1 && BCK == 0){
- myMotor->run(FORWARD);
- myMotor->setSpeed(maxspeed);
- }
- // -------Backward routine ------
- if (BCK == 1 && FWD == 0){
- myMotor->run(BACKWARD);
- myMotor->setSpeed(maxspeed/2);
- }
- // ------ Release motor if no Forward of Backward input ------
- if (FWD == 0 && BCK == 0){
- myMotor->run(RELEASE);
- }
- // ------- Steer Left Routine --------
- if (LFT == 1 && RGT == 0){
- myservo.write(45);
- }
- // ------- Steer Right Routine --------
- if (RGT == 1 && LFT == 0){
- myservo.write(135);
- }
- if (LFT == 0 && RGT == 0 || LFT == 1 && RGT == 1 ){
- myservo.write(90);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement