Beispiel #1
0
void MyBotMotors::Turn(int dir)
{
    Adafruit_MotorShield AFMS = Adafruit_MotorShield();
    Adafruit_DCMotor *motorBR = AFMS.getMotor(1);
    Adafruit_DCMotor *motorBL = AFMS.getMotor(2);
    Adafruit_DCMotor *motorFL = AFMS.getMotor(3);
    Adafruit_DCMotor *motorFR = AFMS.getMotor(4);

    //Right for dir = 1, Left for dir = 0
    if (dir == 1)
    {
        motorFL->run(FORWARD);
        motorFR->run(FORWARD);
        motorBL->run(FORWARD);
        motorBR->run(FORWARD);
    }
    else
    {
        motorFL->run(FORWARD);
        motorFR->run(FORWARD);
        motorBL->run(FORWARD);
        motorBR->run(FORWARD);
    }
}
Beispiel #2
0
#include <Angus_Lib.h>
#include <Adafruit_MotorShield.h>
#include <Wire.h>

// initlize motor 
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor* leftMotor = AFMS.getMotor(LEFT_MOTOR);
Adafruit_DCMotor* rightMotor = AFMS.getMotor(RIGHT_MOTOR);


//pause the program until BUTTON_PIN reads HIGH
void waitForPushButton(){	
	while(analogRead(BUTTON_PIN) <= 900){
		digitalWrite(13, HIGH);
		Serial.println(analogRead(BUTTON_PIN));
		delay(100);
	}
	digitalWrite(13, LOW);
}

bool checkForDog(int angle){
    if (readProximity()) return true;
    turnRightUntil(angle);
	if (readProximity()) return true;
    turnLeftUntil(angle * 2);
	if (readProximity()) return true;
	turnRightUntil(angle);
	return false;
}

Beispiel #3
0
For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/

//#include <Wire.h>
//#include <Adafruit_MotorShield.h>
//#include "utility/Adafruit_PWMServoDriver.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);
//Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);

// You can also make another motor on port M2
Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

void setup() {
  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(150);
  myOtherMotor->setSpeed(150);
Beispiel #4
0
#include <Arduino.h>
#include <Adafruit_MotorShield.h>

/////////////
// DEFINES //
/////////////

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *left_motor = AFMS.getMotor(1);
Adafruit_DCMotor *right_motor = AFMS.getMotor(2);

const uint8_t SPEED = 175;  // percentage [0-255]
const uint16_t DURATION = 500;  // ms

const uint8_t ECHO_PIN = 12;
const uint8_t TRIG_PIN = 13;

const unsigned long DISTANCE_THRESHOLD = 10;  // cm

///////////
// SETUP //
///////////

void setup_motors() {
    left_motor->run(RELEASE);
    right_motor->run(RELEASE);
}

void setup_distance_sensor() {
    pinMode(TRIG_PIN, OUTPUT);
    digitalWrite(TRIG_PIN, LOW);
Beispiel #5
0
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
void setup();
void loop();
#line 1 "src/src.ino"
// See http://friendsoftheunicorn.net/content/raspberry-pi-gertduino-serial
// for information on this file

//#include <Wire.h>
//#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);

int led_pin[6]={13, 9, 10, 3, 5, 6};
int led_state[6]={};
boolean runMotor1 = false;
boolean runMotor2 = false;

void setup()
{
  Serial.begin(9600);
  for(int i=0; i<6; i++)
    pinMode(led_pin[i], OUTPUT);
  motor1->setSpeed(200);
  motor2->setSpeed(200);
}