Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 // Machine UP/DOWN (LEFT) 00004 DigitalOut UP_DOWN_1(P0_8); //8 00005 DigitalOut UP_DOWN_2(P1_25); //25 00006 00007 // Belt Combare Rolling (C_LEFT) 00008 DigitalOut BELT_ROLL_1(P0_2); //2 00009 DigitalOut BELT_ROLL_2(P1_24); //24 00010 00011 // Belt Combare Moving (Upper M/C) 00012 DigitalOut BELT_MOVE_1(P0_0); 00013 DigitalOut BELT_MOVE_2(P1_4); 00014 00015 // Machine Move FW/CFW (C_RIGHT / RIGHT) 00016 DigitalOut FW_CFW_1(P1_27); 00017 DigitalOut FW_CFW_2(P1_18); 00018 00019 // Catch Action (Upper M/C) 00020 DigitalOut CATCH_1(P0_10); 00021 DigitalOut CATCH_2(P0_15); 00022 00023 // LED 00024 DigitalOut led1(LED1); 00025 DigitalOut led2(LED2); 00026 DigitalOut led3(LED3); 00027 DigitalOut led4(LED4); 00028 DigitalOut led5(P0_9); 00029 00030 // Sensor Input 00031 AnalogIn Sensor_read(P0_22); 00032 00033 // Switch Input 00034 DigitalIn UP(P0_12); 00035 DigitalIn DOWN(P0_13); 00036 DigitalIn BELT_ROLL_FW(P0_18); 00037 DigitalIn BELT_ROLL_CFW(P0_19); 00038 DigitalIn BELT_MOVE_FW(P0_17); 00039 DigitalIn BELT_MOVE_CFW(P1_17); 00040 DigitalIn FW(P0_16); 00041 DigitalIn CFW(P0_14); 00042 00043 Ticker wari; 00044 Ticker moto; 00045 00046 char flag = 1; 00047 unsigned char times = 0; 00048 00049 void stop(){ // Interrupt Routine 00050 float sens = Sensor_read; 00051 flag = 1; 00052 if(sens > 0.6){ 00053 UP_DOWN_1 = 1; 00054 UP_DOWN_2 = 1; 00055 led1 = 0; 00056 flag = 0; 00057 } 00058 } 00059 00060 void rev(){ 00061 BELT_ROLL_1 = 0; 00062 BELT_ROLL_2 = 1; 00063 led5 = 1; 00064 } 00065 00066 void matsu(){ 00067 times++; 00068 } 00069 00070 00071 void jikan_1(){ 00072 FW_CFW_2 = 0; 00073 FW_CFW_1 = 1; 00074 led2 = 1; 00075 wait(0.0003); 00076 00077 FW_CFW_1 = 0; 00078 wait(0.001); 00079 } 00080 00081 void jikan_2(){ 00082 FW_CFW_2 = 1; 00083 FW_CFW_1 = 0; 00084 led2 = 1; 00085 wait(0.0003); 00086 FW_CFW_2 = 0; 00087 wait(0.001); 00088 } 00089 00090 int main() { 00091 wari.attach_us(&stop,100000); 00092 moto.attach(&matsu,1); 00093 00094 // rolling 00095 BELT_ROLL_1 = 1; 00096 BELT_ROLL_2 = 0; 00097 00098 while(1){ 00099 if(times == 10){ 00100 rev(); 00101 }else if(times > 11){ 00102 BELT_ROLL_1 = 1; 00103 BELT_ROLL_2 = 0; 00104 led5 = 0; 00105 times = 0; 00106 } 00107 if(flag == 1){ 00108 if(UP == 0 && DOWN == 1){ 00109 UP_DOWN_1 = 1; 00110 UP_DOWN_2 = 0; 00111 led1 = 1; 00112 } 00113 } 00114 00115 if(UP == 1 && DOWN == 0){ 00116 UP_DOWN_1 = 0; 00117 UP_DOWN_2 = 1; 00118 led1 = 1; 00119 }else if(UP == 0 && DOWN == 0){ 00120 UP_DOWN_1 = 1; 00121 UP_DOWN_2 = 1; 00122 led1 = 0; 00123 } 00124 00125 if(FW == 1 && CFW == 0){ 00126 jikan_1(); 00127 }else if(FW == 0 && CFW == 1){ 00128 jikan_2(); 00129 }else if(FW == 0 && CFW == 0){ 00130 FW_CFW_1 = 0; 00131 FW_CFW_2 = 0; 00132 led2 = 0; 00133 } 00134 00135 if(BELT_ROLL_FW == 1 && BELT_ROLL_CFW == 0){ 00136 CATCH_1 = 1; 00137 CATCH_2 = 0; 00138 led4 = 1; 00139 }else if(BELT_ROLL_FW == 0 && BELT_ROLL_CFW == 1){ 00140 CATCH_1 = 0; 00141 CATCH_2 = 1; 00142 led4 = 1; 00143 }else if(BELT_ROLL_FW == 0 && BELT_ROLL_CFW == 0){ 00144 CATCH_1 = 1; 00145 CATCH_2 = 1; 00146 led4 = 0; 00147 } 00148 00149 if(BELT_MOVE_FW == 1 && BELT_MOVE_CFW == 0){ 00150 BELT_MOVE_1 = 1; 00151 BELT_MOVE_2 = 0; 00152 led3 = 1; 00153 }else if(BELT_MOVE_FW == 0 && BELT_MOVE_CFW == 1){ 00154 BELT_MOVE_1 = 0; 00155 BELT_MOVE_2 = 1; 00156 led3 = 1; 00157 }else if(BELT_MOVE_FW == 0 && BELT_MOVE_CFW == 0){ 00158 BELT_MOVE_1 = 1; 00159 BELT_MOVE_2 = 1; 00160 led3 = 0; 00161 } 00162 } 00163 }
Generated on Fri Dec 30 2022 10:01:08 by
1.7.2