Created
March 12, 2014 09:14
-
-
Save andijcr/9503466 to your computer and use it in GitHub Desktop.
Adafruit MotorShield test dc motor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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