LED and button system

Dependencies:   mbed

Fork of LED by CHANG rozen

Committer:
e58136782000
Date:
Fri Oct 20 07:03:43 2017 +0000
Revision:
1:59cafc988b1c
Parent:
0:6e75cf3220cb
Child:
2:7bb4b5066464
open source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rozendhyan 0:6e75cf3220cb 1 #include "mbed.h"
rozendhyan 0:6e75cf3220cb 2
rozendhyan 0:6e75cf3220cb 3 DigitalOut led1(D4);
rozendhyan 0:6e75cf3220cb 4 DigitalOut led2(D5);
rozendhyan 0:6e75cf3220cb 5 DigitalOut led3(D6);
e58136782000 1:59cafc988b1c 6 DigitalIn button(D7);
rozendhyan 0:6e75cf3220cb 7 void LED_Blinkly(DigitalOut led1,DigitalOut led2,DigitalOut led3);
rozendhyan 0:6e75cf3220cb 8 // main() runs in its own thread in the OS
e58136782000 1:59cafc988b1c 9 int main()
e58136782000 1:59cafc988b1c 10 {
e58136782000 1:59cafc988b1c 11 while(1)
e58136782000 1:59cafc988b1c 12 {
e58136782000 1:59cafc988b1c 13
e58136782000 1:59cafc988b1c 14 if(button == true)
e58136782000 1:59cafc988b1c 15 {
e58136782000 1:59cafc988b1c 16 led1 =! led1;
e58136782000 1:59cafc988b1c 17 wait(0.5);
e58136782000 1:59cafc988b1c 18 led2 =! led2;
e58136782000 1:59cafc988b1c 19 wait(0.5);
e58136782000 1:59cafc988b1c 20 led3 =! led3;
e58136782000 1:59cafc988b1c 21 wait(0.5);
e58136782000 1:59cafc988b1c 22 }
e58136782000 1:59cafc988b1c 23 else
e58136782000 1:59cafc988b1c 24 {
e58136782000 1:59cafc988b1c 25 led1 = false;
e58136782000 1:59cafc988b1c 26 led2 = false;
e58136782000 1:59cafc988b1c 27 led3 = false;
e58136782000 1:59cafc988b1c 28 }
e58136782000 1:59cafc988b1c 29 }
e58136782000 1:59cafc988b1c 30 // int sw;
e58136782000 1:59cafc988b1c 31 // printf("1");
e58136782000 1:59cafc988b1c 32 // if(button == true)
e58136782000 1:59cafc988b1c 33 // {
e58136782000 1:59cafc988b1c 34 // sw = 1;
e58136782000 1:59cafc988b1c 35 // }
e58136782000 1:59cafc988b1c 36 // else
e58136782000 1:59cafc988b1c 37 // {
e58136782000 1:59cafc988b1c 38 // sw = 0;
e58136782000 1:59cafc988b1c 39 // }
e58136782000 1:59cafc988b1c 40 // if(sw == 1)
e58136782000 1:59cafc988b1c 41 // {
e58136782000 1:59cafc988b1c 42 // LED_Blinkly(led1,led2,led3);
e58136782000 1:59cafc988b1c 43 // }
e58136782000 1:59cafc988b1c 44 // else
e58136782000 1:59cafc988b1c 45 // {
e58136782000 1:59cafc988b1c 46 // while(false)
e58136782000 1:59cafc988b1c 47 // {
e58136782000 1:59cafc988b1c 48 // led1 = 0;
e58136782000 1:59cafc988b1c 49 // led2 = 0;
e58136782000 1:59cafc988b1c 50 // led3 = 0;
e58136782000 1:59cafc988b1c 51 // printf("off");
e58136782000 1:59cafc988b1c 52 // }
e58136782000 1:59cafc988b1c 53 // }
rozendhyan 0:6e75cf3220cb 54 }
rozendhyan 0:6e75cf3220cb 55 void LED_Blinkly(DigitalOut led1,DigitalOut led2,DigitalOut led3){
rozendhyan 0:6e75cf3220cb 56 while(true){
rozendhyan 0:6e75cf3220cb 57 led1 =! led1;
rozendhyan 0:6e75cf3220cb 58 wait(0.5);
rozendhyan 0:6e75cf3220cb 59 led2 =! led2;
rozendhyan 0:6e75cf3220cb 60 wait(0.5);
rozendhyan 0:6e75cf3220cb 61 led3 =! led3;
rozendhyan 0:6e75cf3220cb 62 wait(0.5);
e58136782000 1:59cafc988b1c 63 printf("on");
rozendhyan 0:6e75cf3220cb 64 }
e58136782000 1:59cafc988b1c 65 }