敦哉 品川
/
limit_switch
This program is about limit switches
Diff: main.cpp
- Revision:
- 0:28ee674a717f
- Child:
- 1:08c96d55206d
diff -r 000000000000 -r 28ee674a717f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 23 01:03:22 2019 +0000 @@ -0,0 +1,95 @@ +#include "mbed.h" +Serial master(PC_6,PC_7); +Serial pc(USBTX,USBRX); +DigitalIn limit1(D9); +DigitalIn limit2(D8); +DigitalIn limit3(D7); +DigitalIn limit4(D6); +DigitalIn limit5(D5); +DigitalIn limit6(D4); +DigitalIn limit7(D2); +DigitalOut green(D12); +DigitalOut yellow(D11); +DigitalOut red(D10); +char data; +void send_data(char send); +int main(){ + + green=1; + + limit1.mode(PullUp); + + limit2.mode(PullUp); + + limit3.mode(PullUp); + + limit4.mode(PullUp); + + limit5.mode(PullUp); + + limit6.mode(PullUp); + + limit7.mode(PullUp); + + while(true){ + + if(!limit1||!limit2){ + + red=1; + + data=0x20; + + send_data(data); + + }else if(!limit3||!limit4){ + + red=1; + + data=0x24; + + send_data(data); + + }else if(!limit5){ + + red=1; + + data=0x28; + + send_data(data); + + }else if(!limit6){ + + red=1; + + data=0x30; + + send_data(data); + + }else if(!limit7){ + + red=1; + + data=0x32; + + send_data(data); + + }else{ + + red=0; + + data=0x34; + + send_data(data); + + } + + + } + + } + +void send_data(char send){ + yellow=1; + master.putc(send); + wait(0.005); + } \ No newline at end of file