#include #include #include #include "Adafruit_ADT7410.h" #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #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); #define TEMP_ADDRESS 0x48 // Create the ADT7410 temperature sensor object Adafruit_ADT7410 tempsensor = Adafruit_ADT7410(); void setup() { Serial.begin(9600); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // setup temp sensor if (!tempsensor.begin(TEMP_ADDRESS)) { Serial.println("Couldn't find ADT7410!"); while (1); } Wire.begin(); display.display(); delay(2000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); // Draw a single pixel in white display.println("FabAcademy 2021"); // Show the display buffer on the screen. You MUST call display() after // drawing commands to make them visible on screen! display.display(); delay(2000); } void loop() { // put your main code here, to run repeatedly: if (tempsensor.readTempC() > 24.0) { Wire.beginTransmission(0x09); Wire.write(1); Wire.endTransmission(); } else { Wire.beginTransmission(0x09); Wire.write(0); Wire.endTransmission(); } display.clearDisplay(); display.setTextSize(3); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.println("Temp:"); display.print(tempsensor.readTempC()); display.display(); // actually display all of the above /* display.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.println(""); display.print("Temperature:"); display.print(random(20, 40)); display.println(" ÂșC"); display.display(); // actually display all of the above */ delay(2000); }