Stap 4: Arduino Code
Deze code bevoegdheden van de motor en verandert tussen de twee modi. De eerste modus is voor continue rotatie en de tweede is voor getimede foto vertraagde's. De knoppen worden gebruikt voor het heen en weer gaan tussen de modi.
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 } }