Étape 4: Arduino Code
Ce code, alimente le moteur et les changements entre les deux modes. Le premier mode est pour rotation continue et le second est pour les photos de retards chronométrés. Les boutons sont utilisés pour aller et venir entre les modes.
int motorPin = 9;//the pin the motor is connected to<br>int buttonPin = 2;//the pin the button is connected to int ledPin = 13;//the pin the LED is connected to boolean currentState = LOW;//stroage for current button state boolean lastState = LOW;//storage for last button state boolean ledState = LOW;//storage for the current state of the LED (off/on)
void setup() { pinMode(motorPin, OUTPUT); pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); }
void loop(){ currentState = digitalRead(buttonPin); if (currentState == HIGH && lastState == LOW){//if button has just been pressed delay(1);//button debouncing //toggle the state of the LED if (ledState == HIGH){ digitalWrite(ledPin, LOW); ledState = LOW; } else { digitalWrite(ledPin, HIGH); ledState = HIGH; } } lastState = currentState; //photo mode if (ledState == LOW){ digitalWrite(motorPin, HIGH); // turns the motor On delay(200); digitalWrite(motorPin, LOW); // turns the motor Off delay(5000); } //video mode if (ledState == HIGH){ int onSpeed = 185; // a number between 0 (stopped) and 255 (full speed) analogWrite(motorPin, onSpeed); // turns the motor On } }