Translate

lunes, 7 de mayo de 2012

Laboratorio # 10

Control de un Servo motor , en 7 posiciones (cada 30°, de 0° a 180°) con un idicador LED , Y controlado por dos pulsadores.


para  realizar este laboratorio necesitamos  7 leds y 7 resistencias , pueden ser de 220 ohmios, también 2 pulsadores y un servomotor .







el montaje es el siguiente :








Código en Arduino:
para controlar el servomotor utilice  la librería Servo y utilice la librería Bounce ,anteriormente mencionada.





Vídeo :

1 comentario:

  1. yo e tratado de hacer algo parecido , a tu control de servo, pero e tenido una dificultad , que no e podido solucionar el servo debe de girar por tiempo hay 3 luces amarillas indican minutos (0,5,10,15) las rojas indican horas hasta (3) ,por lo que se puede establecer hasta un tiempo de 3hrs. 45mint, controlados por pulsadores , uno paraa on /of y los dos restantes minutos hrs, este es el codigo:
    #include

    boolean sessionStarted = false;
    int hours = 0;
    int MAX_HOURS = 3;
    int HOURS_START_PIN = 5;
    int minutes = 0;
    int MAX_MINUTES = 3;
    int MINUTES_START_PIN = 2;
    boolean readingHoursInProgress = false;
    boolean readingMinutesInProgress = false;
    boolean readingSessionBtnInProgress = false;
    unsigned long endTime = 0;
    unsigned long MINUTES_MULTIPLIER = 60000; // 1000 for seconds, 60000 for minutes
    unsigned long HOURS_MULTIPLIER = MINUTES_MULTIPLIER * 60;

    Servo servo;

    void setup() {

    for (int pin = 2; pin <= 7; pin++) {
    pinMode(pin, OUTPUT);
    }
    // SERVO
    servo.attach(9);
    servo.write(0);
    delay(250);
    }

    void loop() {
    if (!sessionStarted) {
    readMinutes();
    readHours();
    showCurrentTime();
    } else {
    if (millis() > endTime) {
    finishSession();
    }
    }

    if (sessionStatusChanged()) {
    if (!sessionStarted) {
    startSession();
    } else {
    finishSession();
    }
    }
    }

    void finishSession() {
    sessionStarted = false;
    servo.write(170);
    fleshLED();
    servo.write(0);
    }

    void startSession() {
    fleshLED();

    sessionStarted = true;
    endTime = minutes * 15 * MINUTES_MULTIPLIER;
    endTime += hours * HOURS_MULTIPLIER;
    endTime += millis();
    }

    void fleshLED() {
    for (int i = 0; i < 5; i++) {
    for (int pin = 2; pin <= 7; pin++) {
    digitalWrite(pin, HIGH);
    }
    delay(500);
    for (int pin = 2; pin <= 7; pin++) {
    digitalWrite(pin, LOW);
    }
    delay(500);
    }
    }

    boolean sessionStatusChanged() {
    int sessionBtnInput = analogRead(A2);

    if (!readingSessionBtnInProgress) {
    if (sessionBtnInput > 1000) {
    readingSessionBtnInProgress = true;
    }
    } else {
    if (sessionBtnInput == 0) {
    readingSessionBtnInProgress = false;
    // react only after user releases button (can be implemented everywhere)
    return true;
    }
    }

    return false;
    }

    void readMinutes() {
    int minInput = analogRead(A0);

    if (!readingMinutesInProgress) {
    if (minInput > 1000) {
    minutes++;
    if (minutes > MAX_MINUTES) {
    minutes = 0;
    }
    readingMinutesInProgress = true;
    }
    } else {
    if (minInput == 0) {
    readingMinutesInProgress = false;
    }
    }
    }

    void readHours() {
    int hrsInput = analogRead(A1);

    if (!readingHoursInProgress) {
    if (hrsInput > 1000) {
    hours++;
    if (hours > MAX_HOURS) {
    hours = 0;
    }
    readingHoursInProgress = true;
    }
    } else {
    if (hrsInput == 0) {
    readingHoursInProgress = false;
    }
    }
    }

    void showCurrentTime() {
    // show minutes
    for (int pin = MINUTES_START_PIN; pin < MINUTES_START_PIN + MAX_MINUTES; pin++) {
    digitalWrite(pin, pin < MINUTES_START_PIN + minutes ? HIGH : LOW);
    }
    // show hours
    for (int pin = HOURS_START_PIN; pin < HOURS_START_PIN + MAX_HOURS; pin++) {
    digitalWrite(pin, pin < HOURS_START_PIN + hours ? HIGH : LOW);
    }
    }


    CUALQUIER COMENTARIO ES BIEN VENIDO HASTA LUEGO

    ResponderEliminar