Skip to content

Instantly share code, notes, and snippets.

@andijcr
Created March 12, 2014 09:14
Show Gist options
  • Save andijcr/9503466 to your computer and use it in GitHub Desktop.
Save andijcr/9503466 to your computer and use it in GitHub Desktop.
Adafruit MotorShield test dc motor
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *sx = AFMS.getMotor(3), *dx =AFMS.getMotor(1);
void setup(){
AFMS.begin();
sx->run(FORWARD);
dx->run(FORWARD);
pinMode(13, OUTPUT);
}
int getmyspeed(){
int val= millis()%9000;
return (val<2000)? 0: (val<7000)? map(val, 2000, 6999, 0, 255) : 255;
}
int stat = HIGH;
void loop(){
delay(100);
stat = stat==HIGH? LOW: HIGH;
digitalWrite(13, stat);
dx->setSpeed(getmyspeed());
sx->setSpeed(getmyspeed());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment