Init Shared Repo
This commit is contained in:
90
src/RoomThermostat.cpp
Normal file
90
src/RoomThermostat.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/* JTR 2020-09-14: Created, Thermostat with User Interface
|
||||
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <DHT_U.h>
|
||||
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
|
||||
// Declaration for SSD1306 display connected using software SPI (default case):
|
||||
#define OLED_CLK 14 // OLED: D0
|
||||
#define OLED_MOSI 13 // OLED: D1
|
||||
#define OLED_RST 22 // OLED: RES
|
||||
#define OLED_DC 17 // (ESP32-"TX2") OLED: DC
|
||||
#define OLED_CS 23 // OLED: CS
|
||||
|
||||
#define DHTPIN 26
|
||||
#define DHTTYPE DHT11 // DHT 11
|
||||
|
||||
#define POTI_IN 27
|
||||
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
delay(1250);
|
||||
|
||||
Serial.println("GO!.");
|
||||
|
||||
dht.begin();
|
||||
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC)) {
|
||||
Serial.println(F("SSD1306 allocation failed"));
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
|
||||
// Show initial display buffer contents on the screen --
|
||||
// the library initializes this with an Adafruit splash screen.
|
||||
display.clearDisplay();
|
||||
display.display();
|
||||
|
||||
display.setTextSize(1); // Normal 1:1 pixel scale
|
||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
||||
display.setCursor(0,0); // Start at top-left corner
|
||||
display.println(F("Starting..."));
|
||||
display.display();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
float h = dht.readHumidity();
|
||||
// Read temperature as Celsius (the default)
|
||||
float t = dht.readTemperature();
|
||||
// Read temperature as Fahrenheit (isFahrenheit = true)
|
||||
float f = dht.readTemperature(true);
|
||||
|
||||
if (isnan(h) || isnan(t) || isnan(f)) {
|
||||
Serial.println(F("Failed to read from DHT sensor!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print(F("Humidity: "));
|
||||
Serial.print(h);
|
||||
Serial.print(F("% Temperature: "));
|
||||
Serial.print(t);
|
||||
Serial.print(F("°C "));
|
||||
Serial.print(f);
|
||||
Serial.println(F("°F"));
|
||||
|
||||
int potiLvl=analogRead(POTI_IN); // -> 0-4095
|
||||
Serial.print("Poti: ");
|
||||
Serial.println(potiLvl);
|
||||
|
||||
display.clearDisplay();
|
||||
|
||||
display.setTextSize(2); // Normal 1:1 pixel scale
|
||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
||||
display.setCursor(0,0); // Start at top-left corner
|
||||
display.println(String(potiLvl));
|
||||
display.display();
|
||||
|
||||
delay(500);
|
||||
}
|
||||
Reference in New Issue
Block a user