ビーンバック回収、テープLED、美少女ボイス担当マイコンのプログラム

Dependencies:   mbed SBDBT arrc_mbed play_mp3

Revision:
1:677d12692be0
Parent:
0:12a2f5f9ab60
Child:
2:9adbf7e03f35
--- a/main.cpp	Sun Jan 30 12:27:02 2022 +0000
+++ b/main.cpp	Thu Feb 03 13:20:16 2022 +0000
@@ -1,27 +1,80 @@
+#include "mbed.h"
 #include "neopixel.h"
-#include "sbdbt.hpp"
+#include "scrp_slave.hpp"
+
+Serial pc(USBTX,USBRX);
+ScrpSlave slave(PC_12,PD_2,PH_1,SERIAL_TX,SERIAL_RX,5);
+NeoPixelOut npx(PB_0,10);
+//モード変更 50 非常停止 51
+bool colormode = 0;
+bool stop = 0;
+int i = 0;
+int j = 0;
 
-NeoPixelOut npx(D12,1);
-sbdbt sb(A0,A1);
-bool mode = 0;
+bool get_changemode(int rx_data,int &tx_data)
+{
+    if(colormode == 0) {
+        colormode = 1;
+    } else {
+        colormode = 0;
+    }
+    return 0;
+}
+
+bool get_stop(int rx_data,int &tx_data)
+{
+    if(stop == 0) {
+        stop = 1;
+        for(i=0; i<npx.numPixels(); i++) {
+            npx.setPixelColor(i,0x000000);
+        }
+    } else {
+        stop = 0;
+    }
+    return 0;
+}
 
-int main(){
-    npx.global_scale = 0.5f;
+int main()
+{
+    slave.addCMD(50,get_changemode);
+    slave.addCMD(51,get_stop);
+    npx.global_scale = 0.05f;
     npx.normalize = false;
-    while(1){
-        if(sb.select() == 1){
-            if(mode == 0){
-                mode = 1;
-            }else if(mode == 1){
-                mode = 0;
+    while(1) {
+        if(stop == 0) {
+            if(colormode == 0) {
+                for(i = 0; i < npx.numPixels(); i++) {
+                    npx.setPixelColor(i,0xFF0000);
+                    npx.show();
+                    pc.printf("control\n");
+                    wait(0.05);
+                    //npx.setPixelColor(i,0x000000);
+                    if(i == npx.numPixels()) {
+                        i = 0;
+                    }
+                }
+            } else if(colormode == 1) {
+                for(i = 0; i < npx.numPixels(); i++) {
+                    npx.setPixelColor(i,0x0000FF);
+                    npx.show();
+                    pc.printf("auto\n");
+                    wait(0.05);
+                    //npx.setPixelColor(i,0x000000);
+                    if(i == npx.numPixels()) {
+                        i = 0;
+                    }
+                }
+            }
+        } else if(stop == 1) {
+            for(i = 0; i < npx.numPixels(); i++) {
+                pc.printf("stopping\n");
+                npx.setPixelColor(i,0x000000);
+                npx.show();
+                wait(0.05);
+                if(i == npx.numPixels()) {
+                    i = 0;
+                }
             }
         }
-            if(mode == 0){
-                npx.setPixelColor(0,0xff0000);
-                npx.show();
-            }else if(mode == 1){
-                npx.setPixelColor(0,0x0000ff);
-                npx.show();
-            }
     }
 }
\ No newline at end of file