Paso 4: Código de Arduino
Este código alimenta el motor y cambia entre los dos modos. El primer modo es para rotación continua y el segundo es para fotos de retardo temporizados. Los botones se utilizan para ir hacia adelante y hacia atrás entre los modos.
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 } }