practica2ejercicio7

Dependencies:   mbed-rtos mbed

Fork of PR2EJ7 by MII1SistElec

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 DigitalOut Led1(PB_3); // Led1 conectado al pin D3
00005 DigitalOut Led2(PB_5); // Led2 conectado al pin D4
00006 DigitalOut Led3(PB_4); // Led3 conectado al pin D5
00007 
00008 void blink1(void const *argument)
00009 {
00010     while (1) {
00011         Led1 = !Led1; //cambiar el Led de estado
00012         Thread::wait(1000); //tiempo de espera para cambiar el led1 de estado
00013     }
00014 }
00015 
00016 void blink2(void const *argument)
00017 {
00018     while (1) {
00019         Led2 = !Led2; //cambiar el Led de estado
00020         Thread::wait(1200); //tiempo de espera para cambiar el led2 de estado
00021     }
00022 }
00023 
00024 void blink3(void const *argument)
00025 {
00026 
00027     while (1) {
00028         Led3 = !Led3; //cambiar el Led de estado
00029         Thread::wait(1500); //tiempo de espera para cambiar el led3 de estado
00030     }
00031 }
00032 
00033 int main()
00034 {
00035     Thread thread1(blink1, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); //forma apropiada de llamar a los Thread
00036     Thread thread2(blink2, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
00037     Thread thread3(blink3, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
00038     while (true) { //código para que el programa no acabe y los Thread sigan ejecutándose
00039 
00040         Thread::wait(500);
00041     }
00042 
00043 }