100 lines
2.4 KiB
C++
100 lines
2.4 KiB
C++
#include <Wire.h>
|
|
#include <BH1750.h>
|
|
#include <dht.h>
|
|
#include <avr/sleep.h>
|
|
#include <Adafruit_GFX.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
dht DHT;
|
|
#define DHT11_PIN 15 //on board: 15 DHT11
|
|
#define VoltPin 18 //on board: 16 GRENN/BLUE
|
|
#define SCREEN_WIDTH 128
|
|
#define SCREEN_HEIGHT 64
|
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
|
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
|
|
|
//VOLTAGE:
|
|
float referenceVoltage = 5.0;
|
|
int maxADCValue = 1023;
|
|
float voltageDividerRatio = 3.0;
|
|
int adcValue = 0;
|
|
float inputVoltage = 0.0;
|
|
float measuredVoltage = 0.0;
|
|
|
|
|
|
BH1750 lightMeter;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
Wire.begin();
|
|
lightMeter.begin();
|
|
pinMode(VoltPin, INPUT);
|
|
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
|
|
display.clearDisplay();
|
|
display.setTextColor(WHITE);
|
|
display.setRotation(0);
|
|
display.setTextSize(3);
|
|
display.setCursor(0, 0);
|
|
display.println("TEST:");
|
|
display.display();
|
|
}
|
|
|
|
void loop() {
|
|
// Serrintln();
|
|
int chk = DHT.read11(DHT11_PIN);
|
|
uint16_t lux = lightMeter.readLightLevel();
|
|
|
|
adcValue = analogRead(VoltPin);
|
|
measuredVoltage = (adcValue * referenceVoltage) / maxADCValue;
|
|
inputVoltage = measuredVoltage * voltageDividerRatio;
|
|
|
|
|
|
// Serial.print("Light: ");
|
|
// Serial.print(lux);
|
|
// Serial.println(" lx");
|
|
// Serial.print("Temp: ");
|
|
// Serial.print(DHT.temperature);
|
|
// Serial.println();
|
|
// Serial.print("Hum: ");
|
|
// Serial.print(DHT.humidity);
|
|
// Serial.println();
|
|
// Serial.print("Volt: ");
|
|
// Serial.print(inputVoltage );
|
|
// Serial.println();
|
|
// Serial.println();
|
|
|
|
|
|
|
|
display.clearDisplay();
|
|
display.setTextSize(1);
|
|
display.setCursor(0, 0);
|
|
display.println("Temp:");
|
|
display.setCursor(30, 0);
|
|
display.println(DHT.temperature);
|
|
display.setCursor(64, 0);
|
|
display.println("Hum:");
|
|
display.setCursor(90, 0);
|
|
display.println(DHT.humidity);
|
|
display.setCursor(0, 32);
|
|
display.println("Volt:");
|
|
display.setCursor(30, 32);
|
|
display.println(inputVoltage);
|
|
display.setCursor(0, 50);
|
|
display.println("adcValue:");
|
|
display.setCursor(64, 50);
|
|
display.println(adcValue);
|
|
|
|
display.setCursor(64, 32);
|
|
display.println("Lux:");
|
|
display.setCursor(90, 32);
|
|
display.println(lux);
|
|
display.display();
|
|
delay(250);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|