This program is about limit switches

Dependencies:   mbed

Committer:
shina
Date:
Thu May 23 01:03:22 2019 +0000
Revision:
0:28ee674a717f
Child:
1:08c96d55206d
This program is about limit switches.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shina 0:28ee674a717f 1 #include "mbed.h"
shina 0:28ee674a717f 2 Serial master(PC_6,PC_7);
shina 0:28ee674a717f 3 Serial pc(USBTX,USBRX);
shina 0:28ee674a717f 4 DigitalIn limit1(D9);
shina 0:28ee674a717f 5 DigitalIn limit2(D8);
shina 0:28ee674a717f 6 DigitalIn limit3(D7);
shina 0:28ee674a717f 7 DigitalIn limit4(D6);
shina 0:28ee674a717f 8 DigitalIn limit5(D5);
shina 0:28ee674a717f 9 DigitalIn limit6(D4);
shina 0:28ee674a717f 10 DigitalIn limit7(D2);
shina 0:28ee674a717f 11 DigitalOut green(D12);
shina 0:28ee674a717f 12 DigitalOut yellow(D11);
shina 0:28ee674a717f 13 DigitalOut red(D10);
shina 0:28ee674a717f 14 char data;
shina 0:28ee674a717f 15 void send_data(char send);
shina 0:28ee674a717f 16 int main(){
shina 0:28ee674a717f 17
shina 0:28ee674a717f 18 green=1;
shina 0:28ee674a717f 19
shina 0:28ee674a717f 20 limit1.mode(PullUp);
shina 0:28ee674a717f 21
shina 0:28ee674a717f 22 limit2.mode(PullUp);
shina 0:28ee674a717f 23
shina 0:28ee674a717f 24 limit3.mode(PullUp);
shina 0:28ee674a717f 25
shina 0:28ee674a717f 26 limit4.mode(PullUp);
shina 0:28ee674a717f 27
shina 0:28ee674a717f 28 limit5.mode(PullUp);
shina 0:28ee674a717f 29
shina 0:28ee674a717f 30 limit6.mode(PullUp);
shina 0:28ee674a717f 31
shina 0:28ee674a717f 32 limit7.mode(PullUp);
shina 0:28ee674a717f 33
shina 0:28ee674a717f 34 while(true){
shina 0:28ee674a717f 35
shina 0:28ee674a717f 36 if(!limit1||!limit2){
shina 0:28ee674a717f 37
shina 0:28ee674a717f 38 red=1;
shina 0:28ee674a717f 39
shina 0:28ee674a717f 40 data=0x20;
shina 0:28ee674a717f 41
shina 0:28ee674a717f 42 send_data(data);
shina 0:28ee674a717f 43
shina 0:28ee674a717f 44 }else if(!limit3||!limit4){
shina 0:28ee674a717f 45
shina 0:28ee674a717f 46 red=1;
shina 0:28ee674a717f 47
shina 0:28ee674a717f 48 data=0x24;
shina 0:28ee674a717f 49
shina 0:28ee674a717f 50 send_data(data);
shina 0:28ee674a717f 51
shina 0:28ee674a717f 52 }else if(!limit5){
shina 0:28ee674a717f 53
shina 0:28ee674a717f 54 red=1;
shina 0:28ee674a717f 55
shina 0:28ee674a717f 56 data=0x28;
shina 0:28ee674a717f 57
shina 0:28ee674a717f 58 send_data(data);
shina 0:28ee674a717f 59
shina 0:28ee674a717f 60 }else if(!limit6){
shina 0:28ee674a717f 61
shina 0:28ee674a717f 62 red=1;
shina 0:28ee674a717f 63
shina 0:28ee674a717f 64 data=0x30;
shina 0:28ee674a717f 65
shina 0:28ee674a717f 66 send_data(data);
shina 0:28ee674a717f 67
shina 0:28ee674a717f 68 }else if(!limit7){
shina 0:28ee674a717f 69
shina 0:28ee674a717f 70 red=1;
shina 0:28ee674a717f 71
shina 0:28ee674a717f 72 data=0x32;
shina 0:28ee674a717f 73
shina 0:28ee674a717f 74 send_data(data);
shina 0:28ee674a717f 75
shina 0:28ee674a717f 76 }else{
shina 0:28ee674a717f 77
shina 0:28ee674a717f 78 red=0;
shina 0:28ee674a717f 79
shina 0:28ee674a717f 80 data=0x34;
shina 0:28ee674a717f 81
shina 0:28ee674a717f 82 send_data(data);
shina 0:28ee674a717f 83
shina 0:28ee674a717f 84 }
shina 0:28ee674a717f 85
shina 0:28ee674a717f 86
shina 0:28ee674a717f 87 }
shina 0:28ee674a717f 88
shina 0:28ee674a717f 89 }
shina 0:28ee674a717f 90
shina 0:28ee674a717f 91 void send_data(char send){
shina 0:28ee674a717f 92 yellow=1;
shina 0:28ee674a717f 93 master.putc(send);
shina 0:28ee674a717f 94 wait(0.005);
shina 0:28ee674a717f 95 }