Paso 5: Sketch de Arduino
Este es el sketch de Arduino utilizado para el control de los sensores, servos y tren.
De disponible en mi github repos: Repositorio de Github
<br><p>/*<br>* Arduino and LEGO Power Functions<br>* dark_storm */ #include #include Servo servoMain; // Define our Servo int curSpeed = 0; // IR led on port 13 LEGOPowerFunctions lego(13); int irPin = 12; int count = 0; int buttonState=0; int fwdRev=0; int stationPin = 2; int buzzerPin = 11; //irPin - Lap Sensor //stationpin -Station Sensor //buzzerpin - Buzzer pin void setup() { Serial.begin(9600); pinMode(irPin, INPUT); pinMode(stationPin,INPUT); servoMain.attach(10); // servo on digital pin 10 pinMode(buzzerPin,OUTPUT); } void loop() { if ( digitalRead(irPin) == 0 ) { count++; delay(3000); } if (count <= 2) { lego.SingleOutput( PWM, PWM_FWD5, RED, CH1); delay(100); if (digitalRead(stationPin) == 0) { lego.SingleOutput( PWM, PWM_FLT, RED, CH1); servoMain.write(0); // Turn Servo Left to 45 degrees delay(2000); tone(11,2000,1000); delay(500); } } else { servoMain.write(90); // Turn Servo Left to 45 degrees count = 0; } }</p>