compartido / Mbed 2 deprecated PR2EJ8

Dependencies:   mbed-rtos mbed

Fork of PR2EJ8 by MII1SistElec

Committer:
carlospomar
Date:
Wed Nov 08 10:38:38 2017 +0000
Revision:
3:7c9e18bcadde
Parent:
2:ff26484331d3
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 2:ff26484331d3 10 int estado1,estado2,estado3;
carlospomar 0:a995f1b1f71c 11
carlospomar 1:c86864e0f17a 12 void pulsador1(void const *argument)
carlospomar 0:a995f1b1f71c 13 {
carlospomar 0:a995f1b1f71c 14 while (1) {
carlospomar 1:c86864e0f17a 15 if (estado1&&(Sw1)) { //verifica el estado del pulsador
carlospomar 0:a995f1b1f71c 16 Led1 = !Sw1; //cambiar el Led de estado
carlospomar 1:c86864e0f17a 17
carlospomar 0:a995f1b1f71c 18 }
carlospomar 1:c86864e0f17a 19 estado1=Sw1;
carlospomar 1:c86864e0f17a 20 Thread::wait(200); //tiempo de espera
carlospomar 0:a995f1b1f71c 21 }
carlospomar 0:a995f1b1f71c 22 }
carlospomar 0:a995f1b1f71c 23
carlospomar 1:c86864e0f17a 24 void pulsador2(void const *argument)
carlospomar 0:a995f1b1f71c 25 {
carlospomar 1:c86864e0f17a 26 while (1) {
carlospomar 1:c86864e0f17a 27 if (estado2&&(Sw2)) { //verifica el estado del pulsador
carlospomar 0:a995f1b1f71c 28 Led2 = !Sw2; //cambiar el Led de estado
carlospomar 1:c86864e0f17a 29
carlospomar 0:a995f1b1f71c 30 }
carlospomar 1:c86864e0f17a 31 estado2=Sw2;
carlospomar 1:c86864e0f17a 32 Thread::wait(200); //tiempo de espera
carlospomar 0:a995f1b1f71c 33 }
carlospomar 0:a995f1b1f71c 34 }
carlospomar 0:a995f1b1f71c 35
carlospomar 1:c86864e0f17a 36 void pulsador3(void const *argument)
carlospomar 0:a995f1b1f71c 37 {
carlospomar 0:a995f1b1f71c 38 while (1) {
carlospomar 1:c86864e0f17a 39 if (estado3&&(Sw3)) { //verifica el estado del pulsador
carlospomar 1:c86864e0f17a 40 Led3 = !Sw3; //cambiar el Led de estado
carlospomar 1:c86864e0f17a 41
carlospomar 0:a995f1b1f71c 42 }
carlospomar 1:c86864e0f17a 43 estado3=Sw3;
carlospomar 1:c86864e0f17a 44 Thread::wait(200); //tiempo de espera
carlospomar 0:a995f1b1f71c 45 }
carlospomar 0:a995f1b1f71c 46 }
carlospomar 0:a995f1b1f71c 47
carlospomar 0:a995f1b1f71c 48
carlospomar 0:a995f1b1f71c 49 int main()
carlospomar 0:a995f1b1f71c 50 {
carlospomar 3:7c9e18bcadde 51 Thread thread1(pulsador1, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
carlospomar 3:7c9e18bcadde 52 Thread thread2(pulsador2, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
carlospomar 3:7c9e18bcadde 53 Thread thread3(pulsador3, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
carlospomar 0:a995f1b1f71c 54 while (true) {
carlospomar 0:a995f1b1f71c 55 Thread::wait(500);
carlospomar 0:a995f1b1f71c 56 }
carlospomar 0:a995f1b1f71c 57 }