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 #include "kbt.h" 00003 #define ROOT 0.2886; 00004 00005 KBT kbt ( PC_10, PC_11); //TX4,RX4 00006 Serial pc( USBTX, USBRX); 00007 00008 PwmOut F (PC_8); //前pwm値 00009 DigitalOut FA (PC_5); 00010 DigitalOut FB (PB_12); 00011 00012 PwmOut R (PC_6); //右pwm値 00013 DigitalOut RA (PB_6); 00014 DigitalOut RB (PC_7); 00015 00016 PwmOut L (PB_14); //左pwm値 00017 DigitalOut LA (PB_15); 00018 DigitalOut LB (PB_1); 00019 00020 void forward(){ 00021 F = 0.5; 00022 R = 0.5; 00023 L = 0.5; 00024 00025 FA = 1; 00026 FB = 1; 00027 RA = 1; 00028 RB = 0; 00029 LA = 0; 00030 LB = 1; 00031 } 00032 00033 void back(){ 00034 F = 0.5; 00035 R = 0.5; 00036 L = 0.5; 00037 00038 FA = 1; 00039 FB = 1; 00040 RA = 0; 00041 RB = 1; 00042 LA = 1; 00043 LB = 0; 00044 } 00045 00046 void leftmove(){ 00047 F = 0.5; 00048 R = ROOT; 00049 L = ROOT; 00050 00051 FA = 1; 00052 FB = 0; 00053 RA = 0; 00054 RB = 1; 00055 LA = 0; 00056 LB = 1; 00057 } 00058 00059 void rightmove(){ 00060 F = 0.5; 00061 R = ROOT; 00062 L = ROOT; 00063 00064 FA = 0; 00065 FB = 1; 00066 RA = 1; 00067 RB = 0; 00068 LA = 1; 00069 LB = 0; 00070 } 00071 00072 void leftrotate(){ 00073 F = 0.5; 00074 R = 0.5; 00075 L = 0.5; 00076 00077 FA = 1; 00078 FB = 0; 00079 RA = 1; 00080 RB = 0; 00081 LA = 1; 00082 LB = 0; 00083 } 00084 00085 void rightrotate(){ 00086 F = 0.5; 00087 R = 0.5; 00088 L = 0.5; 00089 00090 FA = 0; 00091 FB = 1; 00092 RA = 0; 00093 RB = 1; 00094 LA = 0; 00095 LB = 1; 00096 } 00097 00098 void stop(){ 00099 F = 0.5; 00100 R = 0.5; 00101 L = 0.5; 00102 00103 FA = 1; 00104 FB = 1; 00105 RA = 1; 00106 RB = 1; 00107 LA = 1; 00108 LB = 1; 00109 } 00110 00111 int main(){ 00112 kbt.init(2400); 00113 00114 while(true){ 00115 if (kbt.button(up) == 1) forward(); 00116 else if (kbt.button(down) == 1) back(); 00117 else if (kbt.button(right) == 1) rightmove(); 00118 else if (kbt.button(left) == 1) leftmove(); 00119 else if (kbt.button(L1) == 1) rightrotate(); 00120 else if (kbt.button(R1) == 1) leftrotate(); 00121 else stop(); 00122 } 00123 }
Generated on Sun Jul 31 2022 00:01:50 by
1.7.2