Just as a test, added a third screen with graphics.

This commit is contained in:
2026-06-22 17:29:41 +03:00
parent a08228265d
commit be6670b982
5 changed files with 66 additions and 36 deletions
-13
View File
@@ -69,16 +69,3 @@ The physical wiring is already assembled. Current documented wiring is:
## Ground
All component ground pins are connected to common `GND`.
## Assumptions To Verify Later
- The SH1106 module is compatible with the MKR1000 voltage levels
- The AM2302 is powered within its supported operating range
- The button pull-up arrangement matches the intended firmware logic
- Available pins are sufficient for the display, sensor, and both buttons
## Risks To Keep In Mind
- OLED modules may vary by interface and initialization details
- Sensor timing can be sensitive depending on the library used
- Network-based features may require retry logic and fallback screen states
+10
View File
@@ -0,0 +1,10 @@
#ifndef SCREENS_H
#define SCREENS_H
#include <U8g2lib.h>
void drawScreen1(U8G2 &u8g2);
void drawScreen2(U8G2 &u8g2);
void drawWeatherIconScreen(U8G2 &u8g2);
#endif
+2 -2
View File
@@ -5,9 +5,9 @@ const unsigned long pageInterval = 5000;
Carousel::Carousel(Screen *screens, size_t screenCount)
: screens_(screens),
screenCount_(screenCount),
dirty_(true),
currentIndex_(0),
nextUpdate_(pageInterval) {}
nextUpdate_(pageInterval),
dirty_(true) {}
void Carousel::draw(U8G2 &u8g2)
{
+9 -20
View File
@@ -3,32 +3,22 @@
#include <Wire.h>
#include "carousel.h"
#include "screens.h"
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, U8X8_PIN_NONE);
int lastButtonState = LOW;
uint8_t buttonOne = A3;
int number = 0;
bool dirty = true;
void drawScreen1(U8G2 &u8g2) {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0, 20, "Screen 1");
}
void drawScreen2(U8G2 &u8g2) {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0, 40, "Screen 2");
}
int lastButtonNextState = LOW;
uint8_t buttonNext = A3;
Screen screens[] = {
{ drawScreen1 },
{ drawScreen2 }
{ drawScreen2 },
{ drawWeatherIconScreen }
};
Carousel carousel(screens, sizeof(screens) / sizeof(screens[0]));
void setup() {
pinMode(buttonOne, INPUT);
pinMode(buttonNext, INPUT);
u8g2.begin();
u8g2.clearBuffer();
@@ -39,12 +29,11 @@ void loop(){
const unsigned long now = millis();
carousel.update(now);
const int currentButtonState = digitalRead(buttonOne);
if (lastButtonState == LOW && currentButtonState == HIGH) {
number += 10;
const int currentButtonState = digitalRead(buttonNext);
if (lastButtonNextState == LOW && currentButtonState == HIGH) {
carousel.nextScreen();
}
lastButtonState = currentButtonState;
lastButtonNextState = currentButtonState;
if (carousel.consumeDirty()) {
u8g2.clearBuffer();
+44
View File
@@ -0,0 +1,44 @@
#include "screens.h"
namespace
{
void drawSun(U8G2 &u8g2, uint8_t x, uint8_t y)
{
u8g2.drawDisc(x, y, 11);
u8g2.drawLine(x, y - 18, x, y - 14);
u8g2.drawLine(x, y + 14, x, y + 18);
u8g2.drawLine(x - 18, y, x - 14, y);
u8g2.drawLine(x + 14, y, x + 18, y);
u8g2.drawLine(x - 13, y - 13, x - 10, y - 10);
u8g2.drawLine(x + 10, y - 10, x + 13, y - 13);
u8g2.drawLine(x - 13, y + 13, x - 10, y + 10);
u8g2.drawLine(x + 10, y + 10, x + 13, y + 13);
}
void drawCloud(U8G2 &u8g2, uint8_t x, uint8_t y)
{
u8g2.drawDisc(x + 18, y + 14, 12);
u8g2.drawDisc(x + 34, y + 8, 17);
u8g2.drawDisc(x + 52, y + 15, 13);
u8g2.drawBox(x + 17, y + 15, 38, 14);
u8g2.drawRBox(x + 8, y + 18, 58, 15, 7);
}
}
void drawScreen1(U8G2 &u8g2)
{
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0, 20, "Screen 1");
}
void drawScreen2(U8G2 &u8g2)
{
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0, 40, "Screen 2");
}
void drawWeatherIconScreen(U8G2 &u8g2)
{
drawSun(u8g2, 78, 22);
drawCloud(u8g2, 29, 24);
}