可調電阻數值顯示於OLED
可調電阻數值顯示於OLED
材料:
OLED x 1
Arduino x1
可調電阻 x1
可調電阻
------------
VCC +5
OUT A2
GNG GND
OLED
-------------
VCC +5
GND GND
SCL A5
SDA A4
須安裝的庫的可參考
#include <Adafruit_GFX.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <Wire.h>
#define SCREEN_WIDTH 128 // OLED 寬度像素
#define SCREEN_HEIGHT 64 // OLED 高度像素
#define OLED_RESET 4
Adafruit_SSD1306 dispaly(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int o=A2;
int var;
void setup() {
Serial.begin(9600);
pinMode(o, INPUT);
dispaly.begin(SSD1306_SWITCHCAPVCC, 0x3C);
dispaly.clearDisplay();
delay(2000);
}
void loop() {
var=analogRead(o);
var=map(var, 0, 1023, 0, 10);
dispaly.setTextSize(2);
dispaly.setTextColor(WHITE);
dispaly.setCursor(30,20);
dispaly.print(var);
dispaly.setTextSize(2);
dispaly.setCursor(60, 20);
dispaly.println("k ohm");
dispaly.display();
dispaly.clearDisplay();
Serial.println(var);
delay(500);
}
留言
張貼留言