practica2ejercicio8

Dependencies:   mbed-rtos mbed

Fork of PR2EJ8 by MII1SistElec

main.cpp

Committer:
carlospomar
Date:
2017-11-08
Revision:
3:7c9e18bcadde
Parent:
2:ff26484331d3

File content as of revision 3:7c9e18bcadde:

#include "mbed.h"
#include "rtos.h"

DigitalIn Sw1(PB_0); // Switch1 conectado al pin A3
DigitalIn Sw2(PC_1); // Switch2 conectado al pin A4
DigitalIn Sw3(PC_0); // Switch3 conectado al pin A5
DigitalOut Led1(PB_3); // Led1 conectado al pin D3
DigitalOut Led2(PB_5); // Led2 conectado al pin D4
DigitalOut Led3(PB_4); // Led3 conectado al pin D5
int estado1,estado2,estado3;

void pulsador1(void const *argument)
{
    while (1) {
        if (estado1&&(Sw1)) {              //verifica el estado del pulsador
            Led1 = !Sw1;       //cambiar el Led de estado

        }
        estado1=Sw1;
        Thread::wait(200);  //tiempo de espera
    }
}

void pulsador2(void const *argument)
{
     while (1) {
        if (estado2&&(Sw2)) {              //verifica el estado del pulsador
            Led2 = !Sw2;       //cambiar el Led de estado

        }
        estado2=Sw2;
        Thread::wait(200);  //tiempo de espera
    }
}

void pulsador3(void const *argument)
{
    while (1) {
        if (estado3&&(Sw3)) {              //verifica el estado del pulsador
            Led3 = !Sw3;                    //cambiar el Led de estado

        }
        estado3=Sw3;
        Thread::wait(200);  //tiempo de espera
    }
}


int main()
{
    Thread thread1(pulsador1, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
    Thread thread2(pulsador2, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
    Thread thread3(pulsador3, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
    while (true) {
        Thread::wait(500);
    }
}