5659| 3
|
买了个8*8 LED RGB Matrix想结合红外发送跟接收一起用但是不... |
这个是那[size=1.6em]8*8 LED RGB Matrix的链接https://wiki.dfrobot.com.cn/index.php/(SKU:DFR0202)8*8_LED_RGB_Matrix#.E5.9C.A8.E6.8C.87.E5.AE.9A.E5.9B.BE.E5.B1.82.E4.B8.8A.E5.85.A8.E5.B1.8F.E6.98.BE.E7.A4.BA.E5.BD.A9.E8.99.B9 下面是我写的程序 #include <IRremote.h> #include <rgb_matrix.h> #include <SPI.h> #define N_X 1 #define N_Y 1 #define DATA_PIN 11 #define CLK_PIN 13 #define LATCH_PIN 8 rgb_matrix M = rgb_matrix(N_X, N_Y, DATA_PIN, CLK_PIN, LATCH_PIN); IRsend irsend; int flag=1; int RECV_PIN = 12; IRrecv irrecv(RECV_PIN); decode_results results; int K=1; void setup() { // Serial.begin(9600); Serial.begin(115200); M.set_cur(0,0); M.put_char(0,0,'G',MULTIPLY,GREEN,TOP_LAYER); } void hook(void) { if (K==2) M.put_char(0,0,'R',COVER,GREEN+RED,TOP_LAYER); if (K==1) M.put_char(0,0,'G',COVER,GREEN,TOP_LAYER); } void send() { static unsigned long time=millis(); while(flag) {for (int i = 0; i < 3; i++) { irsend.sendSony(1, 12); delay(40);} time=millis(); if(time>150) flag=0; } } void receive() { irrecv.enableIRIn(); static unsigned long time = millis(); static unsigned int sta=0,newsta=0; while(!flag) { if (irrecv.decode(&results)) { Serial.print("Value:"); Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value sta++; //如果收到红外码,则sta加一,否则不进行任何操作 } if(millis()-time>=500) //每隔500ms统计一次sta的值,类似于测频率 { time = millis(); newsta = sta; sta=0; Serial.print("Count:"); Serial.println(newsta); if(newsta>=1) K=results.value; else K=1; if(time>600) flag=1; } } } void loop() { send(); receive(); M.display(hook); } 现在的问题是send()和receive()都只能执行一次然后就一直陷入M.display()死循环,求大神指教,怎么跳出循环,让三个函数轮流执行,又不影响RGB显示效果 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed