Hello everyone, I'm new on this forum, I need your help.
I try different ways to stop 2 motors after 500 ms :
I've tried delay(); millis() and timer().
I'm using Proteus for simulate the code on a ATTiny85, I've attached a photo of the montage.
There is my code :
// ************************************************************
// ATtiny_attachInterrupt.ino
// ************************************************************
// Ce programme est inspire de l exemple donne en page reference
// pour attachInterrupt() en mettant 0 (INT0) a la place de
// digitalPinToInterrupt(pin) qui n est pas accepte pour ATtiny
const byte MotorPin = 0;
const byte Motor2Pin = 1;
const byte interruptPin = 2;
int laststate = 0;
void setup() {
pinMode(MotorPin, OUTPUT);
pinMode(Motor2Pin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(0, blink, FALLING);
}
void loop() {
long int duree=millis();
if (laststate%2==0){
if (millis()-duree<=500){
digitalWrite(MotorPin, 100); //moteur 1 en marche
digitalWrite(Motor2Pin, 0);//moteur 2 à l'arrêt
}
else{
digitalWrite(MotorPin, 0);
digitalWrite(Motor2Pin, 0);
}
}
if (laststate%2!=0){
digitalWrite(MotorPin, 0);
digitalWrite(Motor2Pin, 100);
}
}
void blink() {
laststate=laststate+1;
}
I'm using millis() but it doesn't work.
Please, light on my lantern !