Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created June 16, 2018 13:37
Show Gist options
  • Select an option

  • Save yoggy/08c68dad6cc01eec37d5fd701f887691 to your computer and use it in GitHub Desktop.

Select an option

Save yoggy/08c68dad6cc01eec37d5fd701f887691 to your computer and use it in GitHub Desktop.
//
// m5stack_adc_test.ino
//
// Copyright (c) 2018 yoggy <[email protected]>
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php;//
//
#include <M5Stack.h>
void setup() {
M5.begin();
dacWrite(25, 0); // Speaker OFF
M5.Lcd.fillScreen(BLACK);
// text print
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(7);
M5.Lcd.setCursor(0, 0);
M5.Lcd.printf("AD36val");
}
void loop(){
uint16_t val = analogRead(36); // 0-4095
M5.Lcd.setCursor(0, 56);
M5.Lcd.printf("%d ", val);
uint16_t x = val/(4096/320);
M5.Lcd.fillRect(0, 112, x, 240-112, GREEN);
M5.Lcd.fillRect(x, 112, 320-x, 240-112, BLACK);
if(M5.BtnA.wasPressed()) {
M5.powerOFF();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment