LIGHT.ino 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2022 by M5Stack
  4. * Equipped with M5Core sample source code
  5. * 配套 M5Core 示例源代码
  6. * Visit for more information: https://docs.m5stack.com/en/core/gray
  7. * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
  8. *
  9. * Describe: Light. 环境光传感器
  10. * Date: 2022/2/13
  11. *******************************************************************************
  12. Please connect to Port B,Use the Light Unit screen to display the current
  13. ambient lighting value 请连接端口 B ,使用Light Unit 屏幕显示当前环境光照值。
  14. */
  15. #include <M5Stack.h>
  16. TFT_eSprite img = TFT_eSprite(&M5.Lcd);
  17. void setup() {
  18. M5.begin(); // Init M5Stack. 初始化M5Stack
  19. M5.Power.begin(); // Init power 初始化电源模块
  20. img.setColorDepth(8);
  21. img.createSprite(320, 240); //创建一块320x240的画布
  22. img.setTextSize(2);
  23. pinMode(26, INPUT); // Set pin 26 as input mode. 设置引脚26为输入模式
  24. }
  25. void loop() {
  26. static uint16_t digitalRead_value = 0, analogRead_value = 0;
  27. analogRead_value = analogRead(36); // Store the analog quantity read from
  28. // pin 36. 将36号引脚读取到的模拟量存储
  29. digitalRead_value = digitalRead(
  30. 26); // Store the number read from pin 26. 将26号引脚读取到的数字量存储
  31. img.fillRect(0, 0, 320, 240, 0x00);
  32. img.drawString("UNIT_LIGHT EXAMPLE", 40, 0);
  33. img.setCursor(90, 30);
  34. img.printf("Analog:%d\n", analogRead_value);
  35. img.setCursor(90, 50);
  36. img.printf("Digital:%d\n", digitalRead_value);
  37. img.pushSprite(0, 0); //把画布推送到屏幕(0,0)处
  38. delay(10);
  39. }