Skip to content

How transfer pin settings to setup()? #2620

Open
@mister-Monk

Description

@mister-Monk

There is an ESP8266 and a SSD1309 display.
All GPIO settings are stored in a separate file.
The Wire library is launched after receiving GPIO numbers from SPIFFS, and services some sensors.
How can I change the sketch so that after reading SPIFFS I can pass GPIO numbers to the constructor?

This is a sample.
/*
  GraphicsTest.ino
  Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
*/

//#include <Arduino.h>
#include <U8g2lib.h>

#include <Wire.h>

#define SCL_pin       0            //---------- I2C SCL 0
#define SDA_pin       2            //---------- I2C SDA 2

U8G2_SSD1309_128X64_NONAME0_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL_pin, /* data=*/ SDA_pin, /* reset=*/ U8X8_PIN_NONE);

  uint8_t ssd1309_i       = -1;     // ===== кубики
  bool    ssd1309_c       = true;   // ===== кубики color?

void setup(void)
{
  Wire.begin(SDA_pin, SCL_pin);   // For certain peripherals.
  u8g2.begin();
}

void loop(void)
{
  Draw_Box();
  u8g2.sendBuffer();
  delay(500);
}

void Draw_Box()
{
    if (++ssd1309_i > 7)
    {
      ssd1309_i = 0;
      ssd1309_c = !ssd1309_c;                 // Меняем цвет кубиков
    }
    if (ssd1309_c)  u8g2.setDrawColor(1);     // WHITE
    else            u8g2.setDrawColor(0);     // BLACK
    u8g2.drawBox(ssd1309_i * 16, 0, 15, 16);  // Рисуем кубики
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions