elektro hiof / Mbed 2 deprecated mbed_5_B_3_a

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
00004 Ticker tick1, tick2, tick3, tick4 ;
00005 
00006 volatile int lys1, lys2, lys3, lys4;
00007 Timer timer;
00008 
00009 void lyscontroll_1()
00010 {
00011     lys1=!lys1;
00012 }
00013 void lyscontroll_2()
00014 {
00015     lys2=!lys2;
00016 }
00017 void lyscontroll_3()
00018 {
00019     lys3=!lys3;
00020 }
00021 void lyscontroll_4()
00022 {
00023     lys4=!lys4;
00024 }
00025 int runOnce =1;
00026 int main()
00027 {
00028     timer.start ();
00029     tick1.attach(&lyscontroll_1, 1.0/2);
00030     tick2.attach(&lyscontroll_2, 1.0/6.6);
00031     tick3.attach(&lyscontroll_3, 1.0/14);
00032     
00033 
00034 
00035     while (1) {
00036         led1 = lys1;
00037         led2 = lys2;
00038         led3 = lys3;
00039         led4 = lys4;
00040         if (timer.read()>=10 && runOnce == 1){
00041     tick4.attach(&lyscontroll_4, 1.0/20);
00042     runOnce =0;
00043     }
00044         if (timer.read() >=10) {
00045             tick1.detach();
00046             if (timer.read() >=20) {
00047                 tick2.detach();
00048                 if (timer.read() >=20) {
00049                     tick3.detach();
00050 
00051                 }
00052             }
00053         }
00054     }
00055 }