7805| 4
|
[讨论] app控制蓝牙连接的RGB |
各位盆友你们好,最近做了个RGB的三色灯,调试的时候总是出点小差,故此,想拿上来和各位盆友讨论讨论:) 希望大家不要喷哦,虽然东西垃圾了点:P 讨论点:为什么串口上面的数据会出错(不出错的话应该是0-255)——>因为用的是pwm波调的...? 为什么手机APP发送多组数据后,突然发送后串口上数据不变了(我估计是接收不到了)——>不知道蒙的对不对? 注:串口上面的数据详情看附件 附上一段代码吧-- char state[10]; int x, y , z ; float q, w, e; int led1 = 3; int led2 = 5; int led3 = 6; int led4 = 9; void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); analogWrite(led1, 15); analogWrite(led2, 15); analogWrite(led3, 15); analogWrite(led4, 15); Serial.begin(9600); } void loop() { int j = 0; int i = 0; int mark = 0; while (Serial.available() > 0) //串口获取可用数据 { for (int i = 0; i < 10; i++) { state[i] = char(Serial.read()); //把串口收到的数据寄存到state delay(100); } delay(200); x = (state[1] - 0x30 ) * 100 + (state[2] - 0x30 ) * 10 + (state[3] - 0x30 ) * 1; y = (state[4] - 0x30 ) * 100 + (state[5] - 0x30 ) * 10 + (state[6] - 0x30 ) * 1; z = (state[7] - 0x30 ) * 100 + (state[8] - 0x30 ) * 10 + (state[9] - 0x30 ) * 1; q = x * 2.55; w = y * 2.55; e = z * 2.55; analogWrite(led1, q); analogWrite(led2, w); analogWrite(led3, e); analogWrite(led4, 100); Serial.print(" "); Serial.print(q); Serial.print(" "); Serial.print(w); Serial.print(" "); Serial.println(e); x = 0; y = 0; z = 0; } } |
实际效果图
实际效果图
实际效果图
arduino串口图
arduino串口图
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed