Skip to content

Instantly share code, notes, and snippets.

@ypelletier
Last active January 13, 2019 23:15
Utilisation d'une barriere laser pour déterminer l'accélération d'un objet en chute libre.
/********************************************************
* Photogate
*
* Utilisation d'une barriere laser pour déterminer
* l'accélération d'un objet en chute libre.
*
* Pour plus d'informations:
* http://electroniqueamateur.blogspot.com/2015/04/mesure-de-lacceleration-gavitationnelle.html
*
********************************************************/
#define numero_pin 8 // signal du phototransistor
int etat_precedent = 1; // au départ, le laser devrait passer
int etat_actuel = 1;
unsigned long temps_debut;
int debut = 1; // indique s'il s'agit ou non du début du mouvement
void setup(){
pinMode(numero_pin,INPUT);
Serial.begin(9600);
}
void loop(){
etat_actuel = digitalRead(numero_pin);
if (etat_actuel != etat_precedent){ // on vient de rencontrer un changement d'opacité
if (debut){
temps_debut = millis();
debut = 0;
}
Serial.println(millis() - temps_debut);
etat_precedent = etat_actuel;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment