IR.ino 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. Description: Use IR Unit to receive and test infrared receiving and transmitting
  3. */
  4. #include <M5Stack.h>
  5. // select the input pin for the potentiometer
  6. int ir_recv_pin = 36;
  7. int ir_send_pin = 26;
  8. int last_recv_value = 0;
  9. int cur_recv_value = 0;
  10. void setup() {
  11. M5.begin();
  12. M5.Power.begin();
  13. Serial.begin(115200);
  14. pinMode(ir_recv_pin, INPUT);
  15. pinMode(ir_send_pin, OUTPUT);
  16. //send infrared light
  17. //now, you can see the infrared light through mobile phone camera
  18. digitalWrite(ir_send_pin, 1);
  19. M5.Lcd.setTextSize(2);
  20. M5.Lcd.setCursor(0, 0);
  21. M5.Lcd.print("Test for IR receiver: ");
  22. }
  23. void loop() {
  24. //now, once you press the button on a remote controller to send infrared light
  25. //the screen will display "detected!"
  26. cur_recv_value = digitalRead(ir_recv_pin);
  27. if(last_recv_value != cur_recv_value){
  28. M5.Lcd.setCursor(0, 25);
  29. M5.Lcd.fillRect(0, 25, 150, 25, BLACK);
  30. if(cur_recv_value == 0){//0: detected 1: not detected
  31. M5.Lcd.print("detected!");
  32. }
  33. last_recv_value = cur_recv_value;
  34. }
  35. Serial.println(cur_recv_value);
  36. // delay(100);
  37. }