Newer
Older
M5StickCPlus_FactoryTest2022 / SampleSrc / cds01.ino
@motoki miura motoki miura on 6 Apr 2023 942 bytes use display
#include <M5StickCPlus.h>

#define USE_DISPLAY

int PIN = 26;

// +--- 15kΩ抵抗 --+-- CdSセル --+
// |                            |                       |
// GND                  G26                  3V3
// https://www.storange.jp/2012/03/arduinocds.html

// 注意点: https://lang-ship.com/reference/unofficial/M5StickC/Peripherals/ADC/

void setup() {
  #ifdef USE_DISPLAY
  M5.begin();
  M5.Lcd.setRotation(3);
  #else
  Serial.begin(115200); //M5.beginを使わずにシリアルを使う場合
  #endif
  
  pinMode(PIN, ANALOG); // PINのモード設定
  // https://lang-ship.com/blog/work/m5stickc-io/
}

void loop() {
  int val = analogRead(PIN);
  #ifdef USE_DISPLAY
  M5.Lcd.fillScreen( CYAN );
  M5.Lcd.setCursor(30, 34, 4);  M5.Lcd.setTextSize(2);
  M5.Lcd.setTextColor( WHITE, BLUE );
  M5.Lcd.printf("  %4d  \n CdS ", val);
  #endif
  
  Serial.printf("%04d\n", val ); // 暗 0 〜 4095 明
  delay(300);
  
}