#include "Wire.h"
#include "SHT2x.h"
// include the library code:
#include <LiquidCrystal.h>
#include <U8g2lib.h>
// initialize the library with the numbers of the interface pins
const int rs = 22, en = 23, d4 = 5, d5 = 18, d6 = 19, d7 = 21;
//LiquidCrystal lcd(22, 23, 5, 18, 19, 21);
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, 14, 27, U8X8_PIN_NONE); // All Boards without Reset of the Display
uint32_t start;
uint32_t stop;
SHT2x sht;
const int LED_PIN = 25; // the number of the LED pin
struct Button {
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button1 = {15, 0, false};
Button button2 = {4, 0, false};
void ARDUINO_ISR_ATTR isr(void* arg) {
Button* s = static_cast<Button*>(arg);
s->numberKeyPresses += 1;
s->pressed = true;
}
// Define constants for timing
const unsigned long READ_INTERVAL = 5000; // 1 second interval
unsigned long lastReadTime = 0; // Store the last time the sensor was read
void setup()
{
Serial.begin(115200);+
// Serial.println(__FILE__);
Serial.print("Setup Init\n");
// Serial.println(SHT2x_LIB_VERSION);
pinMode(button1.PIN, INPUT_PULLUP);
attachInterruptArg(button1.PIN, isr, &button1, FALLING);
pinMode(button2.PIN, INPUT_PULLUP);
attachInterruptArg(button2.PIN, isr, &button2, FALLING);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
// set up the LCD's number of columns and rows:
// lcd.begin(16, 2);
// Print a message to the LCD.
// lcd.print("Hello World!");
// sht.begin(12, 13);
// uint8_t stat = sht.getStatus();
// Serial.print(stat, HEX);
// Serial.println();
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(0,10,"Hello World!"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
Serial.print("Loop Init\n");
}
float humidity =0;
float temperature=0;
void loop()
{
if (button1.pressed) {
digitalWrite(LED_PIN, HIGH);
Serial.printf("Button 1 has been pressed Relay ON\n");
button1.pressed = false;
}
if (button2.pressed) {
digitalWrite(LED_PIN, LOW);
Serial.printf("Button 2 has been pressed Relay OFF\n");
button2.pressed = false;
}
// unsigned long currentMillis = millis();
// if (currentMillis - lastReadTime >= READ_INTERVAL) {
// lastReadTime = currentMillis; // Update the last read time
// Read the sensor
// start = micros();
// sht.read();
// stop = micros();
// Read temperature and humidity
// humidity = sht.getHumidity();
// temperature = sht.getTemperature(); // Celsius
// // Clear the display
// u8g2.clearBuffer();
// // Draw the temperature and humidity on the display
// u8g2.setFont(u8g2_font_ncenB08_tr); // Set font
// u8g2.setCursor(1, 10);
// u8g2.print("Temp: ");
// u8g2.print(temperature);
// u8g2.print(" C");
// u8g2.setCursor(2, 30);
// u8g2.print("Humidity: ");
// u8g2.print(humidity);
// u8g2.print(" %");
// // Send the buffer to the display
// u8g2.sendBuffer();
// // Print the elapsed time and sensor values
// Serial.print("\t");
// Serial.print(stop - start);
// Serial.print("\t");
// Serial.print(temperature, 1);
// Serial.print("\t");
// Serial.print(humidity, 1);
// Serial.print("\n");
// // 2x16 character lcd printing data
// // lcd.setCursor(0,0);
// // lcd.print("Temp: ");
// // lcd.print(temperature);
// // lcd.print( (char)223); //Create the degree symbol
// // lcd.print("C");
// // lcd.setCursor(0,1);
// // lcd.print("Humidity: ");
// // lcd.print(humidity);
// // lcd.print("%");
// }
}
// end