ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Codigo en MBED para hacer un reloj con salida por puerto serial


Enviado por   •  25 de Marzo de 2023  •  Tareas  •  885 Palabras (4 Páginas)  •  98 Visitas

Página 1 de 4

/*Programama en MBED para hacer un reloj el caul se le puede controlar el secundero, minutero y horario y lo imprime a través de puerto serial y tan bien gira un servo de 0 a 180° cada minuto.*/

#include "mbed.h"

static BufferedSerial pc(USBTXUSBRX);

InterruptIn col1(PC_7PullDown);

InterruptIn col2(PA_9PullDown);

InterruptIn col3(PA_8PullDown);

InterruptIn col4(PB_10PullDown);

DigitalOut led(LED1);

DigitalOut row1(PB_4);

DigitalOut row2(PB_5);

DigitalOut row3(PB_3);

DigitalOut row4(PA_10);

PwmOut servo(PB_6);

volatile int row = 0;

volatile int col = 0;

volatile char tecla = 'E';

Ticker t;

int s = 0;

int m = 0;

int h = 0;

int duty = 400;

// funcion que se invoca cuando el evento ticker ocurre

void incrementoSegundos() {

  s++;

  duty = duty + 30;

  // servo.write(duty);

  servo.pulsewidth_us(duty);

  if (s == 60) {

    duty = 400;

    s = 0;

    m++;

    if (m == 60) {

      m = 0;

      h++;

      if (h == 24) {

        h = 0;

      }

    }

  }

}

void subeHora() {

  {

    h++;

    if (h == 24) {

      h = 0;

    }

  }

}

// funcion baja hora

void bajaHora() {

  {

    h--;

    if (h == -1) {

      h = 23;

    }

  }

}

// funcion sube minuto

void subeMinuto() {

  {

    m++;

    if (m == 60) {

      m = 0;

    }

  }

}

// funcion baja minuto

void bajaMinuto() {

  {

    m--;

    if (m == -1) {

      m = 59;

    }

  }

}

// funcion sube segundo

void subeSegundo() {

  { s++; }

}

// funcion baja segundo

void bajaSegundo() {

  { s--; }

}

// funcion reiniciar

void reiniciar() {

  {

    h = 0;

    m = 0;

    s = 0;

    duty = 400;

  }

}

// funcion teclado

void key_press() {

  _wait_us_generic(20);

...

Descargar como (para miembros actualizados)  txt (4 Kb)   pdf (27 Kb)   docx (11 Kb)  
Leer 3 páginas más »
Disponible sólo en Clubensayos.com