Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Control de servo, codigo base sin biblioteca
- Lee numeros del 0 al 9 desde el monitor serial siendo
- 0: 0 grados y 9: 180 grados y coloca el servo en la
- posicion requerida.
- Creado el 03/09/2012
- autor: 4m1g0
- */
- const int servo = 9;
- const int reloadTime = 30;
- unsigned int lastPulse;
- int value = 0;
- void setup() {
- pinMode(servo, OUTPUT);
- Serial.begin(9600);
- }
- void loop() {
- if (Serial.available() > 0) {
- value = Serial.read();
- value = value -48;
- Serial.print("He recibido: ");
- Serial.println(value, DEC);
- }
- // control del servo
- if (millis() - lastPulse >= reloadTime)
- {
- Sgiro(value);
- lastPulse = millis();
- }
- delay(2);
- }
- void Sgiro(int value)
- // Coloca al servo en el agulo dado entre 0 y 180 grados
- {
- int pulseWidth = map(value, 0, 9, 500, 2100);
- digitalWrite(servo, HIGH);
- delayMicroseconds(pulseWidth);
- digitalWrite(servo, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment