基于arduino的红外测速

it2022-05-05  142

基于arduinouno的红外测速

#include<LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//使用lcd1602作为显示屏 #include <IRremote.h> int RECV_PIN = 10; IRrecv irrecv(RECV_PIN); decode_results results;//接收红外信号,使用IRremote库 int a = 1, b, c, d, x=1; void setup() { pinMode(17, OUTPUT); lcd.begin(16, 2); lcd.print("The Speed is"); lcd.setCursor(12, 1); lcd.print("km/h");//输出到显示屏 Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver } void loop() { if (irrecv.decode(&results)) { irrecv.resume(); // Receive the next value switch (results.value)//对接受到的红外编码进行判断 { case 0x9716BE3F: if(x==1){ digitalWrite(17, HIGH); delay(50); digitalWrite(17, LOW); Serial.println(results.value, HEX); } b = millis(); x = 0; break; case 0xFF30CF: if(x==1){ digitalWrite(17, HIGH); delay(50); digitalWrite(17, LOW); } b = millis(); x = 0; break; case 0xE318261B: if(x==1){ digitalWrite(17, HIGH); delay(50); digitalWrite(17, LOW); } b = millis(); x = 0; break; case 0x6182021B: // if(x==0) {digitalWrite(17, HIGH); // delay(50); // digitalWrite(17, LOW);} c = millis() - b; d = millis(); // Serial.println(c); // Serial.println(b); // Serial.println(d); lcd.setCursor(0, 1); lcd.print(8000.0 / c * 3.6); if (x == 1) { lcd.setCursor(0, 1); lcd.print("WRONG "); } x = 1; break; case 0xEE886D7F: // if(x==0) {digitalWrite(17, HIGH); // delay(50); // digitalWrite(17, LOW);} c = millis() - b; d = millis(); // Serial.println(c); // Serial.println(b); // Serial.println(d); lcd.setCursor(0, 1); lcd.print(8000.0 / c * 3.6); // delay(50); // digitalWrite(17, HIGH); // delay(50); // digitalWrite(17, LOW); if (x == 1) { lcd.setCursor(0, 1); lcd.print("WRONG "); } x = 1; break; break; case 0xFF7A85: // if(x==0) {digitalWrite(17, HIGH); // delay(50); // digitalWrite(17, LOW);} c = millis() - b; d = millis(); // Serial.println(c); // Serial.println(b); // Serial.println(d); lcd.setCursor(0, 1); lcd.print(8000.0 / c * 3.6); // delay(50); // digitalWrite(17, HIGH); // delay(50); // digitalWrite(17, LOW); if (x == 1) { lcd.setCursor(0, 1); lcd.print("WRONG "); } x = 1; break; } // } // if (a == 0) // { switch (results.value) // { case 0x9716BE3F: // digitalWrite(13, LOW); a = 1; // break; // } // } } }

最新回复(0)