LED 1-4 light based on switch states

Dependencies:   mbed

Committer:
kotachi
Date:
Fri Oct 04 22:52:17 2019 +0000
Revision:
1:ad968bf98003
Parent:
0:105a5c050cb4
Working version of switch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kotachi 0:105a5c050cb4 1 #include "mbed.h"
kotachi 0:105a5c050cb4 2
kotachi 0:105a5c050cb4 3 DigitalIn halls (p8);
kotachi 0:105a5c050cb4 4 DigitalIn pushb (p20);
kotachi 0:105a5c050cb4 5 DigitalOut l1(LED1);
kotachi 0:105a5c050cb4 6 DigitalOut l2(LED2);
kotachi 0:105a5c050cb4 7 DigitalOut l3(LED3);
kotachi 0:105a5c050cb4 8 DigitalOut l4(LED4);
kotachi 0:105a5c050cb4 9 Serial pc(USBTX,USBRX);
kotachi 0:105a5c050cb4 10
kotachi 0:105a5c050cb4 11 int main() {
kotachi 0:105a5c050cb4 12 while(1) {
kotachi 0:105a5c050cb4 13 wait(1);
kotachi 1:ad968bf98003 14 int hall=!halls.read();
kotachi 1:ad968bf98003 15 int push=pushb.read();
kotachi 0:105a5c050cb4 16 int button=hall+push;
kotachi 0:105a5c050cb4 17 switch(button){
kotachi 0:105a5c050cb4 18 case 0:
kotachi 0:105a5c050cb4 19 l1=1;
kotachi 0:105a5c050cb4 20 l2=0;
kotachi 0:105a5c050cb4 21 l3=0;
kotachi 0:105a5c050cb4 22 l4=0;
kotachi 0:105a5c050cb4 23 break;
kotachi 0:105a5c050cb4 24 case 1:
kotachi 0:105a5c050cb4 25 if (push==0) {
kotachi 0:105a5c050cb4 26 l1=0;
kotachi 0:105a5c050cb4 27 l2=1;
kotachi 0:105a5c050cb4 28 l3=0;
kotachi 0:105a5c050cb4 29 l4=0;
kotachi 0:105a5c050cb4 30 }
kotachi 0:105a5c050cb4 31 else {
kotachi 0:105a5c050cb4 32 l1=0;
kotachi 0:105a5c050cb4 33 l2=0;
kotachi 0:105a5c050cb4 34 l3=1;
kotachi 0:105a5c050cb4 35 l4=0;
kotachi 0:105a5c050cb4 36 }
kotachi 0:105a5c050cb4 37 break;
kotachi 0:105a5c050cb4 38 case 2:
kotachi 0:105a5c050cb4 39 l1=0;
kotachi 0:105a5c050cb4 40 l2=0;
kotachi 0:105a5c050cb4 41 l3=0;
kotachi 0:105a5c050cb4 42 l4=1;
kotachi 0:105a5c050cb4 43 break;
kotachi 0:105a5c050cb4 44 }
kotachi 0:105a5c050cb4 45 }
kotachi 0:105a5c050cb4 46 }