Thermo SevenSeg — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by anto2k1.

Components

Sketch code

// File: sketch.ino
// Arduino Uno - DHT11 + OLED SSD1306 128x32 con U8g2 (page buffer)
// Wiring DHT11: VCC->5V, GND->GND, DAT->D2
// Wiring OLED : VCC->5V, GND->GND, SDA->A4, SCL->A5

#include <Wire.h>
#include <U8g2lib.h>
#include <DHT.h>

/* Font 7 segmenti personalizzato */
const uint8_t sevenseg[1139] U8G2_FONT_SECTION("sevenseg") =
  "\20\0\4\4\5\5\5\6\6\21\35\1\353\10\0\0\0\0\0\0\0\2X%D\221GF\216\222B\206"
  "\4#%\254\220(C\242F\10\22DBT\30\42AF\21*Cz\64a\322\244G\23&=\232\60"
  "i\42\245\10\15\11C$\224\20\62\202\204\14\222\202\220\24\243D\225\12\62(`\11\0-\15\256\310K"
  "\26\65,\134\260Q\2\0.\13\307TF\216\22\17Z\224\0\60)\261\307E\216\67M\202,\31\222\244"
  "\310\225xy\266\364x\0\341a%\234\260Q\224xy\344H\221$C\226\4i\363\2\0\61\31h\353"
  "F\206\23Fj\62\210^\15\23\27\36`\60Q\203\350\253a\342\2\62.\261\307E\216\67M\202,\31"
  "\222\244\310\225(I\323|<\0\61j\202\60r\304&\210\42\361\0\206\223\246\353!\247\204$\12\262\252"
  "\315\13\0\63/\261\307E\216\67M\202,\31\222\244\310\225(I\323|<\0\61j\202\60r\304$\214"
  "\22\341\243i\215\22\345\221#E\222\14Y\22\244\315\13\0\64\42\61\307F\206\360\0F\227=\211\227g"
  "K\17Q\23\204\221#&a\224\10\37M\237\217\7 \36D\0\65.\261\307E\216\67M\202\254\21\222"
  "h\310)\322t=\134<\200 \312\30\71b\22F\211\360\321\264F\211\362\310\221\42I\206,\11\322\346"
  "\5\0\66-\261\307E\216\67M\202\254\21\222h\310)\322t=\134<\200 \312\30\71b\42D\11a"
  "\243(\361\362\310\221\42I\206,\11\322\346\5\0\67 p\313F\206'\215\226\204I\42\350\310`z="
  "\134<\200\360\60\11.z\60}=\134<\200\0\70,\261\307E\216\67M\202,\31\222\244\310\225xy"
  "\266\364\20\65A\30\71b\42D\11a\243(\361\362\310\221\42I\206,\11\322\346\5\0\71-\261\307E"
  "\216\67M\202,\31\222\244\310\225xy\266\364\20\65A\30\71b\22F\211\360\321\264F\211\362\310\221\42"
  "I\206,\11\322\346\5\0C&\260\307E\216'-\202,\21\222f\310!\302t<Zxx\270\11\17"
  "@\370h\302t<\344\220\220\64A\26\65yH#\61\307F\206\360\0F\227=\211\227gK\17Q\23"
  "\204\221#&B\224\20\66\212\22/\317\226\36\17 \0\260\34\61\306K\216\67M\202,\31\222\244\310\225"
  "xy\266\364\20\65A\30\71b\246\10\0\0\0\0\4\377\377\0";

// Costruttore per display OLED 128x32 I2C con Page Buffer
U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// Logica alternanza ogni 5 secondi
unsigned long ultimoCambio = 0;
const unsigned long INTERVALLO = 5000UL;
bool mostraTemperatura = true;
float t = 0.0f;
float h = 0.0f;

void setup() {
  Serial.begin(115200);
  dht.begin();
  u8g2.begin();

  // Prima lettura all'avvio
  t = dht.readTemperature();
  h = dht.readHumidity();
}

void loop() {
  // Alterna ogni 5 secondi e aggiorna i valori
  if (millis() - ultimoCambio >= INTERVALLO) {
    ultimoCambio = millis();
    mostraTemperatura = !mostraTemperatura;
    t = dht.readTemperature();
    h = dht.readHumidity();
  }

  // Disegno su display 128x32
  u8g2.firstPage();
  do {
    if (mostraTemperatura) {
      // Intestazione / Icona a sin

More projects by anto2k1