Bonjour
je livre mon code tout laid histoire de...
j'ai donc un montage avec un servo et 1 inté.
quand j'appuie sur l'inte ça incrémente un compteur et fait bouger le servo ...
j'utilise un interrupt pour quand j'appuie sur le bouton... j'ai un bricolage d'anti-rebond... mais le delay ne semble pas fonctionner.
(j'avais rajouté des delay entre 2 Serial.print() et rien...
J'ai raté un truc avec les délais ?
merci plein
// pour ecriveur avec micro servo HD-1440A
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
volatile int pos = 0; // variable to store the servo position
volatile int oldPos = 0;
volatile int compteur= 0;
boolean drapo = false;
volatile int pas = 180 / 10;
const int inteGauche = 7; // en mode auto
// bouton poussoir en 2
void setup()
{
myservo.attach(9,490,2000); // attaches the servo on pin 9 valeur min et max valable pour le modèle
pinMode(inteGauche, INPUT);
//Attach the interrupt to the input pin and monitor for ANY Change
attachInterrupt(0, compose, RISING);
myservo.write(pos);
delay(100);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(inteGauche) == HIGH) {
pos += pas;
if (pos > 180) { pos = 0;}
myservo.write(pos);
Serial.print("Auto: ");
delay(2000);
Serial.println("2 sec + tard");
}
}
void compose() {
compteur ++;
if (digitalRead(inteGauche) == LOW && compteur==2) {
noInterrupts();
delay(15);
Serial.print("depart: ");
pos+= pas;
myservo.write(pos%180);
delay(100);
myservo.write(pos%180);
faitDelai();
Serial.println(pos%180);
interrupts();
compteur = 0;
}
}
void faitDelai() {
delay(10000);
}