Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Last active November 15, 2022 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosarchizo/897aae8adfb769f68a888d50a9905329 to your computer and use it in GitHub Desktop.
Save neosarchizo/897aae8adfb769f68a888d50a9905329 to your computer and use it in GitHub Desktop.
MicroPython - ADC 제어
from machine import Pin, SoftI2C, ADC, Timer
from ssd1306 import SSD1306_I2C
i2c = SoftI2C(sda=Pin(13), scl=Pin(14))
display = SSD1306_I2C(128, 64, i2c, addr=0x3C)
adc = ADC(Pin(36))
def on_timeout(_):
display.fill(0)
display.text('DeviceMart', 0, 0)
display.text('ADC', 0, 15)
value = adc.read() # 12 bits 2^12 = 4096, 0 ~ 4095
display.text(str(value) + ' / 4095', 0, 40)
# 3.3V
display.text(str('%.2f' % ((value / 4095) * 3.3)) + ' V', 0, 55)
display.show()
timer = Timer(-1)
timer.init(period=100, mode=Timer.PERIODIC, callback=on_timeout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment