Projet

Général

Profil

Code Informatique programme compte_tour » main.cpp

Quentin Becarie, 21/07/2020 13:13

 
#include <Arduino.h>
#include <Servo.h>

byte servoPin = 4;
Servo servo;

volatile boolean gachette = HIGH;
volatile float comptageImpuls = 0;
long timeRef = 0;
long delai = 10000;

void ISR()
{
comptageImpuls=comptageImpuls+1;
}

void pilotageMoteur()
{
servo.writeMicroseconds(1610);
}

void declencheGachette()
{
gachette = LOW;
}

void initialisationMoteur()
{
servo.attach(servoPin);
servo.writeMicroseconds(1500); // envoi un 'neutre' au variateur
delay(1000);
servo.writeMicroseconds(2000);
}

void setup()
{
initialisationMoteur();
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(5),declencheGachette,FALLING);
timeRef=millis();
}

void loop()
{
pilotageMoteur();

if (gachette == LOW && (millis()>(timeRef+5)))
{
ISR();
gachette = HIGH;
//t0 = t0+200;
//attachInterrupt(5, gestionINT0, FALLING);
//attachInterrupt (digitalPinToInterrupt (5), ISR, CHANGE);
}

//if(gachette == HIGH){
//delay(2);
//}

if (millis()>(timeRef+delai))
{
timeRef=timeRef+delai;
Serial.print("timeref ="), Serial.println(timeRef), Serial.print(", comptageImpuls ="), Serial.println(comptageImpuls);
Serial.print("Nombre tour par minutes ="), Serial.println(comptageImpuls*1.62);
comptageImpuls=0;
}
}
    (1-1/1)