Kotachi Liu
/
HW1Q2S1
LED 1-4 light based on switch states
main.cpp
- Committer:
- kotachi
- Date:
- 2019-09-30
- Revision:
- 0:105a5c050cb4
- Child:
- 1:ad968bf98003
File content as of revision 0:105a5c050cb4:
#include "mbed.h" DigitalIn halls (p8); DigitalIn pushb (p20); DigitalOut l1(LED1); DigitalOut l2(LED2); DigitalOut l3(LED3); DigitalOut l4(LED4); Serial pc(USBTX,USBRX); int main() { while(1) { wait(1); int hall; int push; halls.read(); pushb.read(); hall=!halls; push=pushb; int button=hall+push; switch(button){ case 0: l1=1; l2=0; l3=0; l4=0; break; case 1: if (push==0) { l1=0; l2=1; l3=0; l4=0; } else { l1=0; l2=0; l3=1; l4=0; } break; case 2: l1=0; l2=0; l3=0; l4=1; break; } } }