Kotachi Liu
/
HW1Q2S1
LED 1-4 light based on switch states
Diff: main.cpp
- Revision:
- 0:105a5c050cb4
- Child:
- 1:ad968bf98003
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 30 17:17:23 2019 +0000 @@ -0,0 +1,50 @@ +#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; + } + } +}