// Jeff Ritchie april 5 20206- written using the following initial prompt on chatgpt // I want to add a second oled and display a different message on it. // The address is o3D // // Jeff Ritchie april 5 20206 for fab academy week 11 // // initial code from chatgpt. I played around with the parameters and added code from hellobuttonblink // #include //library used for I2C // #include //library used for graphics // #include //library used for OLED // #define Button_pin D10 //establishes pin for button // Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire); //first instance of oled display controled by wire // Adafruit_SH1107 display2 = Adafruit_SH1107(32, 128, &Wire); //second instance oled display controled by wire // void setup() { // //setting the intiial display // Serial.begin(115200); //set baud rate // Wire.begin();//begin function for wire // pinMode(Button_pin, INPUT_PULLUP); // button to GND // display2.begin(0x3D, true); //establishes the I2C address of the display // display2.setRotation(1); //sets the roation of the OLED display // display2.clearDisplay(); //clears previous display // display2.setCursor(0, 20); //sets where the message will start- x pixels and y pixels. 0 0 is origin // display2.setTextSize(2); //sets the size of the text to be displayed. 1 is smallest // display2.setTextColor(SH110X_WHITE); //text color // display2.println("Hey world"); //I couldn't fit hello world on the screen at size 2 // display2.display(); //displays instance above. // } // void loop() { // if (digitalRead(Button_pin) == LOW) { //if loop if button is pressed // display.clearDisplay(); //clears previous display // display.setCursor(0, 10); //sets where the message will start- x pixels and 10 pixels down. 0 0 is origin // display.setTextSize(1); //sets the size of the text to be displayed. // display.setTextColor(SH110X_WHITE); //text color // display.println("I said hey there"); // // display.display(); //displays instance above. // delay(200); //debounce button // } // else { // display.clearDisplay(); //clears previous display // display.setCursor(0, 20); //sets where the message will start- x pixels and y pixels. 0 0 is origin // display.setTextSize(2); //sets the size of the text to be displayed. // display.setTextColor(SH110X_WHITE); //text color // display.println("Hey world"); //I couldn't fit hello world on the screen at size 2 // display.display(); //displays instance above. // } // } #include #include #include #include Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire); Adafruit_ADT7410 tempsensor = Adafruit_ADT7410(); unsigned long lastUpdate = 0; const int interval = 500; void setup() { Serial.begin(115200); while (!Serial) { delay(10); } Wire.begin(); Wire.setClock(100000); // set I²C to 100 kHz Serial.println("Before display.begin"); display.begin(0x3C, false); Serial.println("After display.begin"); display.setRotation(1); display.clearDisplay(); display.display(); if (!tempsensor.begin(0x48)) { Serial.println("ADT7410 failed"); while (1); } Serial.println("System ready"); } void loop() { if (millis() - lastUpdate > interval) { lastUpdate = millis(); float tempC = tempsensor.readTempC(); Serial.print("Temp: "); Serial.println(tempC); display.clearDisplay(); // IMPORTANT: reset all text settings every time display.setCursor(0, 20); display.setTextSize(2); display.setTextColor(SH110X_WHITE); display.print(tempC, 1); display.println(" C"); display.display(); } }