#include <Adafruit_NeoPixel.h> // เรียกใช้ไลบรารี่ adafruit
#define PIN 5 // ใช้ พอร์ต 5
#define NUMPIXELS 24 // กำหนดจำนวนหลอดที่ต่อ
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#include "DHTesp.h"
const int DHT_PIN = 14;
DHTesp dhtSensor;
void setup()
{if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);}
delay(2000); // wait two seconds for initializing
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
oled.clearDisplay();
oled.setCursor(20, 4);
oled.setTextSize(2);
oled.setTextColor(BLACK,WHITE);
oled.println(" 20.5 %");
oled.setCursor(0, 24);
oled.setTextSize(3);
oled.setTextColor(WHITE);
oled.println(" 32.5 C");
oled.setCursor(0, 53);
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.println(" GRIT 123456789");
//oled.fillCircle(10,55,5, WHITE);
//oled.drawCircle(30,55,5, WHITE);
//oled.drawTriangle(0,0, 0, 55, 90, 60, WHITE);
oled.drawRect(0,0,127,63, WHITE);
//oled.drawRoundRect(62, 50, 15, 14, 5, WHITE);
oled.display();
}
void loop()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
float hum = data.humidity;
float temp = data.temperature;
oled.clearDisplay();
oled.setCursor(32, 0);
oled.setTextSize(2);
oled.setTextColor(BLACK,WHITE);
oled.println(String(data.humidity, 1) + "%");
oled.setCursor(12,24);
oled.setTextSize(3);
oled.setTextColor(WHITE,BLACK);
oled.println(String(data.temperature, 2) + "C");
oled.setCursor(32,50);
oled.setTextSize(1);
oled.setTextColor(WHITE,BLACK);
oled.println("642021161");
oled.display();
/*
pixels.clear();
pixels.setPixelColor(0, pixels.Color(150, 150, 0));
pixels.show();
delay(200);
pixels.clear();
pixels.setPixelColor(1, pixels.Color(0, 150, 0));
pixels.show();
delay(200);pixels.clear();
pixels.setPixelColor(2, pixels.Color(150, 0, 0));
pixels.show();
delay(200);
*/
}
Loading
ssd1306
ssd1306