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.
Dependencies: mbed line-trace2
Diff: main.cpp
- Revision:
- 0:764148148257
- Child:
- 1:a8fad3c66162
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 01 16:10:49 2018 +0000 @@ -0,0 +1,100 @@ +#include "count.h" + +PwmOut pwm11(D5); //左正転 +PwmOut pwm12(D1); //左逆転 +PwmOut pwm21(D6); //右正転 +PwmOut pwm22(D9); //右逆転 +DigitalOut LED(D2); +InterruptIn button1(A1); //フォトインタラプタ +InterruptIn button2(A2); //フォトインタラプタ +AnalogIn in1(A3); //フォトリフレクタ左 +AnalogIn in2(A4); //フォトリフレクタ真ん中 +AnalogIn in3(A6); //フォトリフレクタ右 + +float thr1 = 0.70f; +float thr2 = 0.70f; +float thr3 = 0.70f; +int judge1 = 0; +int judge2 = 0; +int judge3 = 0; + +int main() { + pwm11.period(0.01f); //100Hz + pwm12.period(0.01f); //100Hz + pwm21.period(0.01f); //100Hz + pwm22.period(0.01f); //100Hz + button1.rise(&flip1); + button2.rise(&flip2); + int n;//3biteで状態を表現 + + while(1) { + + if( count1 + count2 > 43*2*12){ //LEDを点滅 + LED = 1.0f; + wait(0.5f); + LED = 0; + count1 = 0; + count2 = 0; + } +//////////////////float inをint judgeに変換 + if(in1 > thr1){ + judge1 = 1; + } + else{ + judge1 = 0; + } + if(in2 > thr2){ + judge2 = 1; + } + else{ + judge2 = 0; + } + if(in3 > thr3){ + judge3 = 1; + } + else{ + judge3 = 0; + } +///////////////// + n = judge1 + judge2*2 + judge3*4; + + switch(n){ + + case(2)://白黒白進む + pwm11.write(0.60f); + pwm12.write(0.00f); + pwm21.write(0.60f); + pwm22.write(0.00f); + break; + + case(0)://白白白 + pwm11.write(0.10f); + pwm12.write(0.10f); + pwm21.write(0.10f); + pwm22.write(0.10f); + break; + + case(1)://黒白白左回転 + pwm11.write(0.20f); + pwm12.write(0.00f); + pwm21.write(0.00f); + pwm22.write(0.00f); + break; + + case(4)://白白黒右回転 + pwm11.write(0.00f); + pwm12.write(0.00f); + pwm21.write(0.20f); + pwm22.write(0.00f); + break; + + default://それ以外 + pwm11.write(0.00f); + pwm12.write(0.00f); + pwm21.write(0.00f); + pwm22.write(0.00f); + break; + + } + } +} \ No newline at end of file