Hi, i'm using a 5 dc motor with a adafruit shield, everythings is working, but now I want to make a delay with the motors, i don't want to use de Delay() funtion, i'm trying to use mllis() but y don't know how tu used.
What I want to do is, when i turn off the firt motors (previously running) and turn ON the second motors, the firts motors keep running for 3 seconds more.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
void setup() {
Serial.begin(57600);
pwm1.begin();
pwm1.setPWMFreq(100); // This is the maximum PWM frequency
// save I2C bitrate
uint8_t twbrbackup = TWBR;
// must be changed after calling Wire.begin() (inside pwm.begin())
TWBR = 12; // upgrade to 400KHz!
}
void loop() {
//****PWM 1***
if (Serial.available()>0) {
byte input=Serial.read();
if(input == '1'){
pwm1.setPWM(0, 0, 4000);
}
else{
pwm1.setPWM(0, 3500, 0);
}
if(input == '2'){
pwm1.setPWM(2, 0, 4000);
}
else{
pwm1.setPWM(2, 0, 0);
}
if(input == '3'){
pwm1.setPWM(4, 0, 4000);
}
else{
pwm1.setPWM(4, 0, 0);
}