practica2ejercicio8

Dependencies:   mbed-rtos mbed

Committer:
carlospomar
Date:
Mon Nov 06 17:20:46 2017 +0000
Revision:
0:a995f1b1f71c
practica2ejercicio8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
carlospomar 0:a995f1b1f71c 1 #include "mbed.h"
carlospomar 0:a995f1b1f71c 2 #include "rtos.h"
carlospomar 0:a995f1b1f71c 3
carlospomar 0:a995f1b1f71c 4 DigitalIn Sw1(PB_0); // Switch1 conectado al pin A3
carlospomar 0:a995f1b1f71c 5 DigitalIn Sw2(PC_1); // Switch2 conectado al pin A4
carlospomar 0:a995f1b1f71c 6 DigitalIn Sw3(PC_0); // Switch3 conectado al pin A5
carlospomar 0:a995f1b1f71c 7 DigitalOut Led1(PB_3); // Led1 conectado al pin D3
carlospomar 0:a995f1b1f71c 8 DigitalOut Led2(PB_5); // Led2 conectado al pin D4
carlospomar 0:a995f1b1f71c 9 DigitalOut Led3(PB_4); // Led3 conectado al pin D5
carlospomar 0:a995f1b1f71c 10
carlospomar 0:a995f1b1f71c 11 void estado1(void const *argument)
carlospomar 0:a995f1b1f71c 12 {
carlospomar 0:a995f1b1f71c 13 while (1) {
carlospomar 0:a995f1b1f71c 14 if (!Sw1) { //verifica el estado del pulsador
carlospomar 0:a995f1b1f71c 15 Led1 = !Sw1; //cambiar el Led de estado
carlospomar 0:a995f1b1f71c 16 Thread::wait(200); //tiempo de espera
carlospomar 0:a995f1b1f71c 17 }
carlospomar 0:a995f1b1f71c 18 }
carlospomar 0:a995f1b1f71c 19 }
carlospomar 0:a995f1b1f71c 20
carlospomar 0:a995f1b1f71c 21 void estado2(void const *argument)
carlospomar 0:a995f1b1f71c 22 {
carlospomar 0:a995f1b1f71c 23 while (1) {
carlospomar 0:a995f1b1f71c 24 if (!Sw2) { //verifica el estado del pulsador
carlospomar 0:a995f1b1f71c 25 Led2 = !Sw2; //cambiar el Led de estado
carlospomar 0:a995f1b1f71c 26 Thread::wait(200); //tiempo de espera
carlospomar 0:a995f1b1f71c 27 }
carlospomar 0:a995f1b1f71c 28 }
carlospomar 0:a995f1b1f71c 29 }
carlospomar 0:a995f1b1f71c 30
carlospomar 0:a995f1b1f71c 31 void estado3(void const *argument)
carlospomar 0:a995f1b1f71c 32 {
carlospomar 0:a995f1b1f71c 33 while (1) {
carlospomar 0:a995f1b1f71c 34 if (!Sw3) { //verifica el estado del pulsador
carlospomar 0:a995f1b1f71c 35 Led3 = !Sw3; //cambiar el Led de estado
carlospomar 0:a995f1b1f71c 36 Thread::wait(200); //tiempo de espera
carlospomar 0:a995f1b1f71c 37 }
carlospomar 0:a995f1b1f71c 38 }
carlospomar 0:a995f1b1f71c 39 }
carlospomar 0:a995f1b1f71c 40
carlospomar 0:a995f1b1f71c 41
carlospomar 0:a995f1b1f71c 42 int main()
carlospomar 0:a995f1b1f71c 43 {
carlospomar 0:a995f1b1f71c 44 Thread thread1(estado1, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
carlospomar 0:a995f1b1f71c 45 Thread thread2(estado2, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
carlospomar 0:a995f1b1f71c 46 Thread thread3(estado3, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
carlospomar 0:a995f1b1f71c 47 while (true) {
carlospomar 0:a995f1b1f71c 48 Thread::wait(500);
carlospomar 0:a995f1b1f71c 49 }
carlospomar 0:a995f1b1f71c 50 }