Ci-dessous, vous trouverez notre code pour programmer le moteur.
#include <Stepper.h> const int stepsPerRevolution = 200; int photoPin = A0; int photocellREADING; Stepper analyzer(200, 12,13); const int pwmA = 3; const int pwmB = 11; const int brakeA = 9; const int brakeB = 8; const int dirA = 12; const int dirB = 13; void setup() { Serial.begin(9600); pinMode(pwmA, OUTPUT); pinMode(pwmB, OUTPUT); pinMode(brakeA, OUTPUT); pinMode(brakeB, OUTPUT); digitalWrite(pwmA, HIGH); digitalWrite(pwmB, HIGH); digitalWrite(brakeA, LOW); digitalWrite(brakeB, LOW); analyzer.setSpeed(50); } void loop() { photocellREADING= analogRead(photoPin); Serial.println(photocellREADING); delay(200); if(photocellREADING > 25){ analyzer.step(100); delay(1000); } else{ analyzer.step(-100);