Загрузка данных


// Sda A4
// scl A5
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// analog
#define GASPIN 0
#define TEMPSENSOR 1


///digital
#define BUZZ 13
#define RELE 12

String Labels[] = {"Gas level: ", "Temperature: ", "Watersplash: "};

bool splash = false;

void print_onscreen(int gas, int temp){

  display.clearDisplay();
  display.setCursor(1, 1);
  display.println("Data:");
  for (int index = 0; index < 3; index++) {
    String text;
    int y_pos = 16 + (index * 16); 
    display.setCursor(1, y_pos);
    
    
    display.print(Labels[index]);
    if (index == 0) {text = String(gas);}
    if (index == 1) {text = String(temp);}
    if (index == 2) {text = String(splash);}
    display.print(text);
  }
  display.display();
}
void setup() {
  pinMode(BUZZ, OUTPUT);
  pinMode(RELE, OUTPUT);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    return;
  }
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  digitalWrite(BUZZ, HIGH);
  delay(500);
  digitalWrite(BUZZ, LOW);
  delay(500);
  display.setCursor(0, 20);
  display.println("Welcome to");
  display.println("fire-defense manager");
  display.display();
  delay(5000);
  display.clearDisplay();
  display.println("Data:");
}

void loop() {
  int gaslevel = analogRead(GASPIN);
  int templevel = analogRead(TEMPSENSOR);
  print_onscreen(gaslevel, templevel);

}