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