![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
ビーンバック回収、テープLED、美少女ボイス担当マイコンのプログラム
Dependencies: mbed SBDBT arrc_mbed play_mp3
main.cpp@4:925391180349, 2022-03-11 (annotated)
- Committer:
- sopuranoaruto
- Date:
- Fri Mar 11 05:18:10 2022 +0000
- Revision:
- 4:925391180349
- Parent:
- 3:4d2a0e4bb4d9
- Child:
- 5:200723c2d111
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sopuranoaruto | 1:677d12692be0 | 1 | #include "mbed.h" |
sopuranoaruto | 0:12a2f5f9ab60 | 2 | #include "neopixel.h" |
sopuranoaruto | 4:925391180349 | 3 | #include "mp3.hpp" |
sopuranoaruto | 1:677d12692be0 | 4 | #include "scrp_slave.hpp" |
sopuranoaruto | 1:677d12692be0 | 5 | |
sopuranoaruto | 1:677d12692be0 | 6 | Serial pc(USBTX,USBRX); |
sopuranoaruto | 1:677d12692be0 | 7 | ScrpSlave slave(PC_12,PD_2,PH_1,SERIAL_TX,SERIAL_RX,5); |
sopuranoaruto | 4:925391180349 | 8 | NeoPixelOut npx(PB_0,16); |
sopuranoaruto | 4:925391180349 | 9 | Playmp3 mp3(PA_0,PA_1); |
sopuranoaruto | 4:925391180349 | 10 | bool areamode = 0; |
sopuranoaruto | 1:677d12692be0 | 11 | bool colormode = 0; |
sopuranoaruto | 1:677d12692be0 | 12 | bool stop = 0; |
sopuranoaruto | 4:925391180349 | 13 | bool start = 0; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 14 | |
sopuranoaruto | 1:677d12692be0 | 15 | int i = 0; |
sopuranoaruto | 0:12a2f5f9ab60 | 16 | |
sopuranoaruto | 4:925391180349 | 17 | //農作物回収 1 |
sopuranoaruto | 4:925391180349 | 18 | bool play1(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 19 | { |
sopuranoaruto | 4:925391180349 | 20 | if(rx_data == 1) { |
sopuranoaruto | 4:925391180349 | 21 | mp3.set_number_of_tracks(1); |
sopuranoaruto | 4:925391180349 | 22 | } |
sopuranoaruto | 4:925391180349 | 23 | return true; |
sopuranoaruto | 4:925391180349 | 24 | } |
sopuranoaruto | 4:925391180349 | 25 | |
sopuranoaruto | 4:925391180349 | 26 | //農作物設置 2 |
sopuranoaruto | 4:925391180349 | 27 | bool play2(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 28 | { |
sopuranoaruto | 4:925391180349 | 29 | if(rx_data == 1) { |
sopuranoaruto | 4:925391180349 | 30 | mp3.set_number_of_tracks(2); |
sopuranoaruto | 4:925391180349 | 31 | } |
sopuranoaruto | 4:925391180349 | 32 | return true; |
sopuranoaruto | 4:925391180349 | 33 | } |
sopuranoaruto | 4:925391180349 | 34 | |
sopuranoaruto | 4:925391180349 | 35 | //ビーンバック回収 3 |
sopuranoaruto | 4:925391180349 | 36 | bool play3(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 37 | { |
sopuranoaruto | 4:925391180349 | 38 | if(rx_data == 1) { |
sopuranoaruto | 4:925391180349 | 39 | mp3.set_number_of_tracks(3); |
sopuranoaruto | 4:925391180349 | 40 | } |
sopuranoaruto | 4:925391180349 | 41 | return true; |
sopuranoaruto | 4:925391180349 | 42 | } |
sopuranoaruto | 4:925391180349 | 43 | |
sopuranoaruto | 4:925391180349 | 44 | //自動運転モードに移行 4 |
sopuranoaruto | 4:925391180349 | 45 | bool play4(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 46 | { |
sopuranoaruto | 4:925391180349 | 47 | if(rx_data == 1) { |
sopuranoaruto | 4:925391180349 | 48 | mp3.set_number_of_tracks(4); |
sopuranoaruto | 4:925391180349 | 49 | } |
sopuranoaruto | 4:925391180349 | 50 | return true; |
sopuranoaruto | 4:925391180349 | 51 | } |
sopuranoaruto | 4:925391180349 | 52 | |
sopuranoaruto | 4:925391180349 | 53 | //ビーンバック発射 5 |
sopuranoaruto | 4:925391180349 | 54 | bool play5(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 55 | { |
sopuranoaruto | 4:925391180349 | 56 | if(rx_data == 1) { |
sopuranoaruto | 4:925391180349 | 57 | mp3.set_number_of_tracks(5); |
sopuranoaruto | 4:925391180349 | 58 | } |
sopuranoaruto | 4:925391180349 | 59 | return true; |
sopuranoaruto | 4:925391180349 | 60 | } |
sopuranoaruto | 4:925391180349 | 61 | |
sopuranoaruto | 2:9adbf7e03f35 | 62 | //モード変更 50 |
sopuranoaruto | 1:677d12692be0 | 63 | bool get_changemode(int rx_data,int &tx_data) |
sopuranoaruto | 1:677d12692be0 | 64 | { |
sopuranoaruto | 4:925391180349 | 65 | if(rx_data == 0) { |
sopuranoaruto | 4:925391180349 | 66 | if(colormode == 1) { |
sopuranoaruto | 4:925391180349 | 67 | colormode = 0; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 68 | } |
sopuranoaruto | 1:677d12692be0 | 69 | } else { |
sopuranoaruto | 4:925391180349 | 70 | if(colormode == 0) { |
sopuranoaruto | 4:925391180349 | 71 | colormode = 1; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 72 | } |
sopuranoaruto | 1:677d12692be0 | 73 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 74 | return true; |
sopuranoaruto | 1:677d12692be0 | 75 | } |
sopuranoaruto | 1:677d12692be0 | 76 | |
sopuranoaruto | 2:9adbf7e03f35 | 77 | //非常停止 51 |
sopuranoaruto | 1:677d12692be0 | 78 | bool get_stop(int rx_data,int &tx_data) |
sopuranoaruto | 1:677d12692be0 | 79 | { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 80 | if(rx_data == 0) { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 81 | stop = 0; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 82 | } else { |
sopuranoaruto | 1:677d12692be0 | 83 | stop = 1; |
sopuranoaruto | 1:677d12692be0 | 84 | for(i=0; i<npx.numPixels(); i++) { |
sopuranoaruto | 1:677d12692be0 | 85 | npx.setPixelColor(i,0x000000); |
sopuranoaruto | 1:677d12692be0 | 86 | } |
sopuranoaruto | 1:677d12692be0 | 87 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 88 | return true; |
sopuranoaruto | 1:677d12692be0 | 89 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 90 | |
sopuranoaruto | 4:925391180349 | 91 | //エリアチェンジ 52 |
sopuranoaruto | 4:925391180349 | 92 | bool get_areachange(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 93 | { |
sopuranoaruto | 4:925391180349 | 94 | if(rx_data == 0) { |
sopuranoaruto | 4:925391180349 | 95 | if(areamode == 1) { |
sopuranoaruto | 4:925391180349 | 96 | areamode = 0; |
sopuranoaruto | 4:925391180349 | 97 | } |
sopuranoaruto | 4:925391180349 | 98 | } else { |
sopuranoaruto | 4:925391180349 | 99 | if(areamode == 0) { |
sopuranoaruto | 4:925391180349 | 100 | areamode = 1; |
sopuranoaruto | 4:925391180349 | 101 | } |
sopuranoaruto | 4:925391180349 | 102 | } |
sopuranoaruto | 4:925391180349 | 103 | return true; |
sopuranoaruto | 4:925391180349 | 104 | } |
sopuranoaruto | 4:925391180349 | 105 | |
sopuranoaruto | 4:925391180349 | 106 | //スタート 10 |
sopuranoaruto | 4:925391180349 | 107 | bool get_start(int rx_data,int &tx_data) |
sopuranoaruto | 4:925391180349 | 108 | { |
sopuranoaruto | 4:925391180349 | 109 | if(rx_data == 0) { |
sopuranoaruto | 4:925391180349 | 110 | if(start == 1) { |
sopuranoaruto | 4:925391180349 | 111 | start = 0; |
sopuranoaruto | 4:925391180349 | 112 | } |
sopuranoaruto | 4:925391180349 | 113 | } else { |
sopuranoaruto | 4:925391180349 | 114 | if(start == 0) { |
sopuranoaruto | 4:925391180349 | 115 | start = 1; |
sopuranoaruto | 4:925391180349 | 116 | } |
sopuranoaruto | 4:925391180349 | 117 | } |
sopuranoaruto | 4:925391180349 | 118 | return true; |
sopuranoaruto | 4:925391180349 | 119 | } |
sopuranoaruto | 4:925391180349 | 120 | |
sopuranoaruto | 1:677d12692be0 | 121 | int main() |
sopuranoaruto | 1:677d12692be0 | 122 | { |
sopuranoaruto | 4:925391180349 | 123 | //農作物回収 |
sopuranoaruto | 4:925391180349 | 124 | slave.addCMD(1,play1); |
sopuranoaruto | 4:925391180349 | 125 | //農作物設置 |
sopuranoaruto | 4:925391180349 | 126 | slave.addCMD(2,play2); |
sopuranoaruto | 4:925391180349 | 127 | //ビーンバック回収 |
sopuranoaruto | 4:925391180349 | 128 | slave.addCMD(3,play3); |
sopuranoaruto | 4:925391180349 | 129 | //自動運転モードに移行 |
sopuranoaruto | 4:925391180349 | 130 | slave.addCMD(4,play4); |
sopuranoaruto | 4:925391180349 | 131 | //ビーンバック発射 |
sopuranoaruto | 4:925391180349 | 132 | slave.addCMD(5,play5); |
sopuranoaruto | 4:925391180349 | 133 | //スタート |
sopuranoaruto | 4:925391180349 | 134 | slave.addCMD(10,get_start); |
sopuranoaruto | 2:9adbf7e03f35 | 135 | //モード変更 |
sopuranoaruto | 1:677d12692be0 | 136 | slave.addCMD(50,get_changemode); |
sopuranoaruto | 2:9adbf7e03f35 | 137 | //非常停止 |
sopuranoaruto | 1:677d12692be0 | 138 | slave.addCMD(51,get_stop); |
sopuranoaruto | 4:925391180349 | 139 | //エリア変更 |
sopuranoaruto | 4:925391180349 | 140 | slave.addCMD(52,get_areachange); |
sopuranoaruto | 2:9adbf7e03f35 | 141 | //光の強さ |
sopuranoaruto | 1:677d12692be0 | 142 | npx.global_scale = 0.05f; |
sopuranoaruto | 2:9adbf7e03f35 | 143 | //信号来ていないときは光らない |
sopuranoaruto | 0:12a2f5f9ab60 | 144 | npx.normalize = false; |
sopuranoaruto | 4:925391180349 | 145 | //音量セット |
sopuranoaruto | 4:925391180349 | 146 | mp3.set_volume(255); |
sopuranoaruto | 4:925391180349 | 147 | //クワイエットモードOFF |
sopuranoaruto | 4:925391180349 | 148 | mp3.quiet_mode(false); |
sopuranoaruto | 4:925391180349 | 149 | |
sopuranoaruto | 1:677d12692be0 | 150 | while(1) { |
sopuranoaruto | 2:9adbf7e03f35 | 151 | //非常停止解除 |
sopuranoaruto | 1:677d12692be0 | 152 | if(stop == 0) { |
sopuranoaruto | 4:925391180349 | 153 | if(start == 0) { |
sopuranoaruto | 4:925391180349 | 154 | //フィールド赤 |
sopuranoaruto | 4:925391180349 | 155 | if(areamode == 0) { |
sopuranoaruto | 4:925391180349 | 156 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 4:925391180349 | 157 | npx.setPixelColor(i,0xFF0000); |
sopuranoaruto | 4:925391180349 | 158 | npx.show(); |
sopuranoaruto | 4:925391180349 | 159 | wait(0.05); |
sopuranoaruto | 1:677d12692be0 | 160 | } |
sopuranoaruto | 4:925391180349 | 161 | pc.printf("red area\n"); |
sopuranoaruto | 4:925391180349 | 162 | //フィールド青 |
sopuranoaruto | 4:925391180349 | 163 | } else if(areamode == 1) { |
sopuranoaruto | 4:925391180349 | 164 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 4:925391180349 | 165 | npx.setPixelColor(i,0x0000FF); |
sopuranoaruto | 4:925391180349 | 166 | npx.show(); |
sopuranoaruto | 4:925391180349 | 167 | wait(0.05); |
sopuranoaruto | 4:925391180349 | 168 | } |
sopuranoaruto | 4:925391180349 | 169 | pc.printf("bule area\n"); |
sopuranoaruto | 1:677d12692be0 | 170 | } |
sopuranoaruto | 4:925391180349 | 171 | } else { |
sopuranoaruto | 4:925391180349 | 172 | //手動モード 黄色 |
sopuranoaruto | 4:925391180349 | 173 | if(colormode == 0) { |
sopuranoaruto | 4:925391180349 | 174 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 4:925391180349 | 175 | npx.setPixelColor(i,0xFFF100); |
sopuranoaruto | 4:925391180349 | 176 | npx.show(); |
sopuranoaruto | 4:925391180349 | 177 | wait(0.05); |
sopuranoaruto | 4:925391180349 | 178 | if(i == npx.numPixels()) { |
sopuranoaruto | 4:925391180349 | 179 | i = 0; |
sopuranoaruto | 4:925391180349 | 180 | } |
sopuranoaruto | 4:925391180349 | 181 | } |
sopuranoaruto | 4:925391180349 | 182 | pc.printf("control\n"); |
sopuranoaruto | 4:925391180349 | 183 | //自動モード 緑 |
sopuranoaruto | 4:925391180349 | 184 | } else if(colormode == 1) { |
sopuranoaruto | 4:925391180349 | 185 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 4:925391180349 | 186 | npx.setPixelColor(i,0x00FF00); |
sopuranoaruto | 4:925391180349 | 187 | npx.show(); |
sopuranoaruto | 4:925391180349 | 188 | wait(0.05); |
sopuranoaruto | 4:925391180349 | 189 | if(i == npx.numPixels()) { |
sopuranoaruto | 4:925391180349 | 190 | i = 0; |
sopuranoaruto | 4:925391180349 | 191 | } |
sopuranoaruto | 4:925391180349 | 192 | } |
sopuranoaruto | 1:677d12692be0 | 193 | pc.printf("auto\n"); |
sopuranoaruto | 1:677d12692be0 | 194 | } |
sopuranoaruto | 1:677d12692be0 | 195 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 196 | //非常停止 |
sopuranoaruto | 1:677d12692be0 | 197 | } else if(stop == 1) { |
sopuranoaruto | 1:677d12692be0 | 198 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 1:677d12692be0 | 199 | npx.setPixelColor(i,0x000000); |
sopuranoaruto | 1:677d12692be0 | 200 | npx.show(); |
sopuranoaruto | 1:677d12692be0 | 201 | wait(0.05); |
sopuranoaruto | 1:677d12692be0 | 202 | if(i == npx.numPixels()) { |
sopuranoaruto | 1:677d12692be0 | 203 | i = 0; |
sopuranoaruto | 1:677d12692be0 | 204 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 205 | } |
sopuranoaruto | 4:925391180349 | 206 | pc.printf("stopping\n"); |
sopuranoaruto | 0:12a2f5f9ab60 | 207 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 208 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 209 | } |