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
Fork of photosensor by
Diff: main.cpp
- Revision:
- 1:09c7cfcb680a
- Parent:
- 0:149ad32ad819
- Child:
- 2:4f9ed1327327
--- a/main.cpp Thu Oct 11 16:17:38 2018 +0000
+++ b/main.cpp Sat Oct 13 07:50:16 2018 +0000
@@ -4,9 +4,12 @@
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut flash(LED4);
-DigitalIn test(p15);
-int flag;
-float run;
+DigitalIn test(p15); //ここでピン15からの電圧の値、つまりフォトインタラプタが何か遮るものを検知すればハイの1を返して、
+ //何もないつまりスリットの部分ではローの0を返す。それを変数testに代入している
+int flag; //変数flagを整数で型づけする。これがスイッチで、1の間は瞬間は何もしないけど、
+ //スリットの間隔であるπ/4とタイヤの半径70mmつまり一つのスリットを通過するごとに52.5mm加算していく必要があるから
+ //0になった瞬間はこれを総距離に加えるというスイッチの役割をする。
+float run; //変数runをフロートで型づけする
void rise1() {
led1 = !led1;
@@ -17,21 +20,22 @@
}
int main() {
- while(1) {
- printf("%d\r\n", test.read());
- if (test.read() == 1 and flag == 0){
- flag = 1;
+ while(1) { //常にtrueとして以下の作業を繰り返す
+ printf("%d\r\n", test.read()); //ピン15から読み込んだtestを読み込んでそれを表示する。だからずーっとだーって0か1が表示される
+ if (test.read() == 1 and flag == 0){ //もしtestが1つまり何か障害物があって、かつflagが0つまりスイッチが切れているときは
+ flag = 1; //この時はスイッチを1に切る。ただ障害物があるかつスイッチが1で切れているときはそのまま
}
- else if (test.read() == 0 and flag == 1){
- flag = 0;
- run += 52.5;
+ else if (test.read() == 0 and flag == 1){ //そうじゃなくて今度はとうとうtestが0でスリットの部分になった瞬間なのにスイッチが1で切れているときは
+ flag = 0; //まずこれでスイッチを0にして入れる。
+ //こうすることで同じスリットの中でtestが複数回0を返した時に何回も52.5mmを加算しつづけるということがなくなる
+ run += 52.5; //総距離runに52.5を加算する
}
- if (run > 250){
- break;
+ if (run > 250){ //もし総距離が250以上ならば、というのもここの値は暫定値。とりあえずゴール地点が決まればまたその値に修正する
+ break; //つまりゴールについたらこのループからぬける
}
// wait_us(1);
}
- printf("%f\r\n", run);
+ printf("%f\r\n", run); //最後に総距離runを表示する。下のは少し動作確認で使ったプログラムやから今回にはあまり関係ない
// button1.rise(&rise1);
// button1.fall(&fall1);
// printf("hello world\r\n");
