![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
テープLEDのプログラム 改良により色、光り方などに変化の可能性有り
Dependencies: mbed SBDBT arrc_mbed play_mp3
シリアル通信可
赤コート -> 赤 青コート -> 青 自動モード -> 黄 手動モード -> 緑
美少女ボイス搭載
シリアル通信に多少のラグが発生する可能性がある。
main.cpp@3:4d2a0e4bb4d9, 2022-03-08 (annotated)
- Committer:
- sopuranoaruto
- Date:
- Tue Mar 08 01:30:51 2022 +0000
- Revision:
- 3:4d2a0e4bb4d9
- Parent:
- 2:9adbf7e03f35
- Child:
- 4:925391180349
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 | 1:677d12692be0 | 3 | #include "scrp_slave.hpp" |
sopuranoaruto | 1:677d12692be0 | 4 | |
sopuranoaruto | 1:677d12692be0 | 5 | Serial pc(USBTX,USBRX); |
sopuranoaruto | 1:677d12692be0 | 6 | ScrpSlave slave(PC_12,PD_2,PH_1,SERIAL_TX,SERIAL_RX,5); |
sopuranoaruto | 1:677d12692be0 | 7 | NeoPixelOut npx(PB_0,10); |
sopuranoaruto | 1:677d12692be0 | 8 | bool colormode = 0; |
sopuranoaruto | 1:677d12692be0 | 9 | bool stop = 0; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 10 | |
sopuranoaruto | 1:677d12692be0 | 11 | int i = 0; |
sopuranoaruto | 0:12a2f5f9ab60 | 12 | |
sopuranoaruto | 2:9adbf7e03f35 | 13 | //モード変更 50 |
sopuranoaruto | 1:677d12692be0 | 14 | bool get_changemode(int rx_data,int &tx_data) |
sopuranoaruto | 1:677d12692be0 | 15 | { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 16 | if(rx_data == 1) { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 17 | if(colormode == 0){ |
sopuranoaruto | 3:4d2a0e4bb4d9 | 18 | colormode = 1; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 19 | } |
sopuranoaruto | 1:677d12692be0 | 20 | } else { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 21 | if(colormode == 1){ |
sopuranoaruto | 3:4d2a0e4bb4d9 | 22 | colormode = 0; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 23 | } |
sopuranoaruto | 1:677d12692be0 | 24 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 25 | return true; |
sopuranoaruto | 1:677d12692be0 | 26 | } |
sopuranoaruto | 1:677d12692be0 | 27 | |
sopuranoaruto | 2:9adbf7e03f35 | 28 | //非常停止 51 |
sopuranoaruto | 1:677d12692be0 | 29 | bool get_stop(int rx_data,int &tx_data) |
sopuranoaruto | 1:677d12692be0 | 30 | { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 31 | if(rx_data == 0) { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 32 | stop = 0; |
sopuranoaruto | 3:4d2a0e4bb4d9 | 33 | } else { |
sopuranoaruto | 1:677d12692be0 | 34 | stop = 1; |
sopuranoaruto | 1:677d12692be0 | 35 | for(i=0; i<npx.numPixels(); i++) { |
sopuranoaruto | 1:677d12692be0 | 36 | npx.setPixelColor(i,0x000000); |
sopuranoaruto | 1:677d12692be0 | 37 | } |
sopuranoaruto | 1:677d12692be0 | 38 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 39 | return true; |
sopuranoaruto | 1:677d12692be0 | 40 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 41 | |
sopuranoaruto | 1:677d12692be0 | 42 | int main() |
sopuranoaruto | 1:677d12692be0 | 43 | { |
sopuranoaruto | 2:9adbf7e03f35 | 44 | //モード変更 |
sopuranoaruto | 1:677d12692be0 | 45 | slave.addCMD(50,get_changemode); |
sopuranoaruto | 2:9adbf7e03f35 | 46 | //非常停止 |
sopuranoaruto | 1:677d12692be0 | 47 | slave.addCMD(51,get_stop); |
sopuranoaruto | 2:9adbf7e03f35 | 48 | //光の強さ |
sopuranoaruto | 1:677d12692be0 | 49 | npx.global_scale = 0.05f; |
sopuranoaruto | 2:9adbf7e03f35 | 50 | //信号来ていないときは光らない |
sopuranoaruto | 0:12a2f5f9ab60 | 51 | npx.normalize = false; |
sopuranoaruto | 1:677d12692be0 | 52 | while(1) { |
sopuranoaruto | 2:9adbf7e03f35 | 53 | //非常停止解除 |
sopuranoaruto | 1:677d12692be0 | 54 | if(stop == 0) { |
sopuranoaruto | 1:677d12692be0 | 55 | if(colormode == 0) { |
sopuranoaruto | 3:4d2a0e4bb4d9 | 56 | //手動モード 赤 |
sopuranoaruto | 1:677d12692be0 | 57 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 1:677d12692be0 | 58 | npx.setPixelColor(i,0xFF0000); |
sopuranoaruto | 1:677d12692be0 | 59 | npx.show(); |
sopuranoaruto | 1:677d12692be0 | 60 | pc.printf("control\n"); |
sopuranoaruto | 1:677d12692be0 | 61 | wait(0.05); |
sopuranoaruto | 1:677d12692be0 | 62 | if(i == npx.numPixels()) { |
sopuranoaruto | 1:677d12692be0 | 63 | i = 0; |
sopuranoaruto | 1:677d12692be0 | 64 | } |
sopuranoaruto | 1:677d12692be0 | 65 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 66 | //自動モード 青 |
sopuranoaruto | 1:677d12692be0 | 67 | } else if(colormode == 1) { |
sopuranoaruto | 1:677d12692be0 | 68 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 1:677d12692be0 | 69 | npx.setPixelColor(i,0x0000FF); |
sopuranoaruto | 1:677d12692be0 | 70 | npx.show(); |
sopuranoaruto | 1:677d12692be0 | 71 | pc.printf("auto\n"); |
sopuranoaruto | 1:677d12692be0 | 72 | wait(0.05); |
sopuranoaruto | 1:677d12692be0 | 73 | if(i == npx.numPixels()) { |
sopuranoaruto | 1:677d12692be0 | 74 | i = 0; |
sopuranoaruto | 1:677d12692be0 | 75 | } |
sopuranoaruto | 1:677d12692be0 | 76 | } |
sopuranoaruto | 1:677d12692be0 | 77 | } |
sopuranoaruto | 3:4d2a0e4bb4d9 | 78 | //非常停止 |
sopuranoaruto | 1:677d12692be0 | 79 | } else if(stop == 1) { |
sopuranoaruto | 1:677d12692be0 | 80 | for(i = 0; i < npx.numPixels(); i++) { |
sopuranoaruto | 1:677d12692be0 | 81 | pc.printf("stopping\n"); |
sopuranoaruto | 1:677d12692be0 | 82 | npx.setPixelColor(i,0x000000); |
sopuranoaruto | 1:677d12692be0 | 83 | npx.show(); |
sopuranoaruto | 1:677d12692be0 | 84 | wait(0.05); |
sopuranoaruto | 1:677d12692be0 | 85 | if(i == npx.numPixels()) { |
sopuranoaruto | 1:677d12692be0 | 86 | i = 0; |
sopuranoaruto | 1:677d12692be0 | 87 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 88 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 89 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 90 | } |
sopuranoaruto | 0:12a2f5f9ab60 | 91 | } |