![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
4/2にちゃんと動いたやつ
Dependencies: mbed SBDBT arrc_mbed
main.cpp@8:e76d6c16d7af, 2022-03-11 (annotated)
- Committer:
- guesta
- Date:
- Fri Mar 11 04:21:06 2022 +0000
- Revision:
- 8:e76d6c16d7af
- Parent:
- 7:59be95fceafa
- Child:
- 10:4fe47396eb5a
new_ver;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
guesta | 0:d8faed605a5c | 1 | #include "mbed.h" |
guesta | 3:e4b5563563af | 2 | #include "scrp_slave.hpp" |
guesta | 3:e4b5563563af | 3 | #include "sbdbt.hpp" |
guesta | 8:e76d6c16d7af | 4 | #include "mp3.hpp" |
guesta | 0:d8faed605a5c | 5 | |
guesta | 0:d8faed605a5c | 6 | int main(){ |
guesta | 1:642ee25ea489 | 7 | //---------------初期設定--------------- |
guesta | 3:e4b5563563af | 8 | //scrp_slave |
guesta | 3:e4b5563563af | 9 | ScrpSlave scrp(PC_12,PD_2,PH_1,0x0807f800); |
guesta | 6:fd9b59f828e8 | 10 | |
guesta | 3:e4b5563563af | 11 | //sbdbt |
guesta | 8:e76d6c16d7af | 12 | sbdbt sb(PA_0,PA_1); |
guesta | 6:fd9b59f828e8 | 13 | |
guesta | 3:e4b5563563af | 14 | //scrp_slaveのid設定 |
guesta | 6:fd9b59f828e8 | 15 | const int wheel_num = 1; |
guesta | 3:e4b5563563af | 16 | const int BeanbagGet_num = 2; |
guesta | 3:e4b5563563af | 17 | const int BeanbagShot_num = 3; |
guesta | 3:e4b5563563af | 18 | const int TakoGetPut_num = 4; |
guesta | 8:e76d6c16d7af | 19 | const int remort_stop_num = 5; |
guesta | 6:fd9b59f828e8 | 20 | const int send_all = 255; |
guesta | 6:fd9b59f828e8 | 21 | |
guesta | 3:e4b5563563af | 22 | //コマンド番号設定 |
guesta | 6:fd9b59f828e8 | 23 | //足回り用 |
guesta | 3:e4b5563563af | 24 | const int x_component_cmd = 1; |
guesta | 3:e4b5563563af | 25 | const int y_component_cmd = 2; |
guesta | 3:e4b5563563af | 26 | const int l2_cmd = 3; |
guesta | 3:e4b5563563af | 27 | const int r2_cmd = 4; |
guesta | 7:59be95fceafa | 28 | const int l1_cmd = 5; |
guesta | 6:fd9b59f828e8 | 29 | |
guesta | 6:fd9b59f828e8 | 30 | //ビーンバッグ回収用 |
guesta | 8:e76d6c16d7af | 31 | const int move = 1; |
guesta | 6:fd9b59f828e8 | 32 | |
guesta | 6:fd9b59f828e8 | 33 | //ビーンバッグ発射用 |
guesta | 8:e76d6c16d7af | 34 | const int shot = 2; |
guesta | 6:fd9b59f828e8 | 35 | |
guesta | 6:fd9b59f828e8 | 36 | //農作物回収・設置用 |
guesta | 6:fd9b59f828e8 | 37 | const int up = 1; |
guesta | 6:fd9b59f828e8 | 38 | const int down = 2; |
guesta | 8:e76d6c16d7af | 39 | const int limit1 = 3; |
guesta | 8:e76d6c16d7af | 40 | const int limit2 = 4; |
guesta | 6:fd9b59f828e8 | 41 | |
guesta | 6:fd9b59f828e8 | 42 | //テープLED用 |
guesta | 6:fd9b59f828e8 | 43 | |
guesta | 6:fd9b59f828e8 | 44 | //遠隔非常停止受信用 |
guesta | 6:fd9b59f828e8 | 45 | |
guesta | 6:fd9b59f828e8 | 46 | //全体送信用 |
guesta | 6:fd9b59f828e8 | 47 | const int select = 50;//手動・自動切り替え |
guesta | 6:fd9b59f828e8 | 48 | const int stop_all = 51;//全プログラム停止 |
guesta | 6:fd9b59f828e8 | 49 | |
guesta | 1:642ee25ea489 | 50 | //変数 |
guesta | 7:59be95fceafa | 51 | bool auto_mode = false; |
guesta | 7:59be95fceafa | 52 | bool auto_start; |
guesta | 3:e4b5563563af | 53 | int x_component; |
guesta | 3:e4b5563563af | 54 | int y_component; |
guesta | 3:e4b5563563af | 55 | int l2_num; |
guesta | 3:e4b5563563af | 56 | int r2_num; |
guesta | 8:e76d6c16d7af | 57 | |
guesta | 8:e76d6c16d7af | 58 | //mp3 |
guesta | 8:e76d6c16d7af | 59 | Playmp3 voice(PA_9,PA_10); |
guesta | 8:e76d6c16d7af | 60 | int volume = 200;//音量 |
guesta | 8:e76d6c16d7af | 61 | int track; |
guesta | 8:e76d6c16d7af | 62 | voice.set_volume(200); |
guesta | 8:e76d6c16d7af | 63 | voice.quiet_mode(false); |
guesta | 8:e76d6c16d7af | 64 | |
guesta | 8:e76d6c16d7af | 65 | DigitalIn sw1(PB_4); |
guesta | 8:e76d6c16d7af | 66 | DigitalIn sw2(PB_5); |
guesta | 8:e76d6c16d7af | 67 | sw1.mode(PullUp); |
guesta | 8:e76d6c16d7af | 68 | sw2.mode(PullUp); |
guesta | 8:e76d6c16d7af | 69 | |
guesta | 8:e76d6c16d7af | 70 | //count |
guesta | 8:e76d6c16d7af | 71 | int count_up; |
guesta | 8:e76d6c16d7af | 72 | int count_down; |
guesta | 8:e76d6c16d7af | 73 | int count_shot; |
guesta | 8:e76d6c16d7af | 74 | int count_auto; |
guesta | 3:e4b5563563af | 75 | //------------------------------------- |
guesta | 6:fd9b59f828e8 | 76 | |
guesta | 1:642ee25ea489 | 77 | while(true){ |
guesta | 8:e76d6c16d7af | 78 | printf("%d\n",sw1.read()); |
guesta | 8:e76d6c16d7af | 79 | |
guesta | 3:e4b5563563af | 80 | sb.button_state(); |
guesta | 6:fd9b59f828e8 | 81 | x_component = sb.rsx(); |
guesta | 6:fd9b59f828e8 | 82 | y_component = sb.rsy(); |
guesta | 3:e4b5563563af | 83 | l2_num = sb.l2An(); |
guesta | 3:e4b5563563af | 84 | r2_num = sb.r2An(); |
guesta | 8:e76d6c16d7af | 85 | if(sb.select() == 1){ |
guesta | 8:e76d6c16d7af | 86 | count_auto++; |
guesta | 8:e76d6c16d7af | 87 | if(count_auto == 1){ |
guesta | 8:e76d6c16d7af | 88 | auto_mode =! auto_mode; |
guesta | 8:e76d6c16d7af | 89 | } |
guesta | 8:e76d6c16d7af | 90 | }else{ |
guesta | 8:e76d6c16d7af | 91 | count_auto = 0; |
guesta | 7:59be95fceafa | 92 | } |
guesta | 6:fd9b59f828e8 | 93 | |
guesta | 6:fd9b59f828e8 | 94 | //足回り |
guesta | 3:e4b5563563af | 95 | scrp.send1(wheel_num,x_component_cmd,x_component); |
guesta | 7:59be95fceafa | 96 | wait_ms(2); |
guesta | 3:e4b5563563af | 97 | scrp.send1(wheel_num,y_component_cmd,y_component); |
guesta | 7:59be95fceafa | 98 | wait_ms(2); |
guesta | 3:e4b5563563af | 99 | scrp.send1(wheel_num,l2_cmd,l2_num); |
guesta | 7:59be95fceafa | 100 | wait_ms(2); |
guesta | 3:e4b5563563af | 101 | scrp.send1(wheel_num,r2_cmd,r2_num); |
guesta | 7:59be95fceafa | 102 | wait_ms(2); |
guesta | 7:59be95fceafa | 103 | scrp.send1(wheel_num,l1_cmd,sb.l1()); |
guesta | 7:59be95fceafa | 104 | wait_ms(2); |
guesta | 6:fd9b59f828e8 | 105 | |
guesta | 6:fd9b59f828e8 | 106 | //ビーンバッグ回収 |
guesta | 8:e76d6c16d7af | 107 | scrp.send1(BeanbagGet_num,move,sb.square()); |
guesta | 8:e76d6c16d7af | 108 | wait_ms(2); |
guesta | 6:fd9b59f828e8 | 109 | |
guesta | 6:fd9b59f828e8 | 110 | //ビーンバッグ発射 |
guesta | 7:59be95fceafa | 111 | if(auto_mode == true){ |
guesta | 8:e76d6c16d7af | 112 | scrp.send1(BeanbagShot_num,shot,sb.square()); |
guesta | 7:59be95fceafa | 113 | wait_ms(2); |
guesta | 8:e76d6c16d7af | 114 | if(sb.square() == 1){ |
guesta | 8:e76d6c16d7af | 115 | count_shot++; |
guesta | 8:e76d6c16d7af | 116 | if(count_shot == 1){ |
guesta | 8:e76d6c16d7af | 117 | voice.set_number_of_tracks(5); |
guesta | 8:e76d6c16d7af | 118 | } |
guesta | 8:e76d6c16d7af | 119 | }else{ |
guesta | 8:e76d6c16d7af | 120 | count_shot = 0; |
guesta | 8:e76d6c16d7af | 121 | } |
guesta | 7:59be95fceafa | 122 | } |
guesta | 6:fd9b59f828e8 | 123 | |
guesta | 6:fd9b59f828e8 | 124 | //農作物回収・設置 |
guesta | 8:e76d6c16d7af | 125 | if(sb.up() == 1){ |
guesta | 8:e76d6c16d7af | 126 | count_up++; |
guesta | 8:e76d6c16d7af | 127 | if(count_up == 1){ |
guesta | 8:e76d6c16d7af | 128 | voice.set_number_of_tracks(1); |
guesta | 8:e76d6c16d7af | 129 | } |
guesta | 8:e76d6c16d7af | 130 | }else{ |
guesta | 8:e76d6c16d7af | 131 | count_up = 0; |
guesta | 8:e76d6c16d7af | 132 | } |
guesta | 8:e76d6c16d7af | 133 | if(sb.down() == 1){ |
guesta | 8:e76d6c16d7af | 134 | count_down++; |
guesta | 8:e76d6c16d7af | 135 | if(count_down == 1){ |
guesta | 8:e76d6c16d7af | 136 | voice.set_number_of_tracks(2); |
guesta | 8:e76d6c16d7af | 137 | } |
guesta | 8:e76d6c16d7af | 138 | }else{ |
guesta | 8:e76d6c16d7af | 139 | count_down = 0; |
guesta | 8:e76d6c16d7af | 140 | } |
guesta | 8:e76d6c16d7af | 141 | scrp.send1(TakoGetPut_num,up,sb.up()); |
guesta | 8:e76d6c16d7af | 142 | wait_ms(2); |
guesta | 8:e76d6c16d7af | 143 | scrp.send1(TakoGetPut_num,down,sb.down()); |
guesta | 8:e76d6c16d7af | 144 | wait_ms(2); |
guesta | 8:e76d6c16d7af | 145 | if(sw1.read() == 0){ |
guesta | 8:e76d6c16d7af | 146 | scrp.send1(TakoGetPut_num,limit1,1); |
guesta | 8:e76d6c16d7af | 147 | }else{ |
guesta | 8:e76d6c16d7af | 148 | scrp.send1(TakoGetPut_num,limit1,0); |
guesta | 8:e76d6c16d7af | 149 | } |
guesta | 8:e76d6c16d7af | 150 | wait_ms(2); |
guesta | 8:e76d6c16d7af | 151 | if(sw2.read() == 0){ |
guesta | 8:e76d6c16d7af | 152 | scrp.send1(TakoGetPut_num,limit2,1); |
guesta | 8:e76d6c16d7af | 153 | }else{ |
guesta | 8:e76d6c16d7af | 154 | scrp.send1(TakoGetPut_num,limit2,0); |
guesta | 8:e76d6c16d7af | 155 | } |
guesta | 8:e76d6c16d7af | 156 | wait_ms(2); |
guesta | 6:fd9b59f828e8 | 157 | |
guesta | 6:fd9b59f828e8 | 158 | //全体送信 |
guesta | 7:59be95fceafa | 159 | scrp.send1(send_all,select,auto_mode);//自動・手動モード切り替え |
guesta | 8:e76d6c16d7af | 160 | wait_ms(2); |
guesta | 1:642ee25ea489 | 161 | } |
guesta | 0:d8faed605a5c | 162 | } |