Just as a test, added a third screen with graphics.
This commit is contained in:
@@ -69,16 +69,3 @@ The physical wiring is already assembled. Current documented wiring is:
|
|||||||
## Ground
|
## Ground
|
||||||
|
|
||||||
All component ground pins are connected to common `GND`.
|
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
|
|
||||||
|
|||||||
@@ -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
|
||||||
+3
-3
@@ -5,9 +5,9 @@ const unsigned long pageInterval = 5000;
|
|||||||
Carousel::Carousel(Screen *screens, size_t screenCount)
|
Carousel::Carousel(Screen *screens, size_t screenCount)
|
||||||
: screens_(screens),
|
: screens_(screens),
|
||||||
screenCount_(screenCount),
|
screenCount_(screenCount),
|
||||||
dirty_(true),
|
|
||||||
currentIndex_(0),
|
currentIndex_(0),
|
||||||
nextUpdate_(pageInterval) {}
|
nextUpdate_(pageInterval),
|
||||||
|
dirty_(true) {}
|
||||||
|
|
||||||
void Carousel::draw(U8G2 &u8g2)
|
void Carousel::draw(U8G2 &u8g2)
|
||||||
{
|
{
|
||||||
@@ -33,4 +33,4 @@ void Carousel::update(unsigned long now) {
|
|||||||
if (now > nextUpdate_) {
|
if (now > nextUpdate_) {
|
||||||
nextScreen();
|
nextScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-20
@@ -3,32 +3,22 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
#include "carousel.h"
|
#include "carousel.h"
|
||||||
|
#include "screens.h"
|
||||||
|
|
||||||
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, U8X8_PIN_NONE);
|
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, U8X8_PIN_NONE);
|
||||||
|
|
||||||
int lastButtonState = LOW;
|
int lastButtonNextState = LOW;
|
||||||
uint8_t buttonOne = A3;
|
uint8_t buttonNext = 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
Screen screens[] = {
|
Screen screens[] = {
|
||||||
{ drawScreen1 },
|
{ drawScreen1 },
|
||||||
{ drawScreen2 }
|
{ drawScreen2 },
|
||||||
|
{ drawWeatherIconScreen }
|
||||||
};
|
};
|
||||||
Carousel carousel(screens, sizeof(screens) / sizeof(screens[0]));
|
Carousel carousel(screens, sizeof(screens) / sizeof(screens[0]));
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(buttonOne, INPUT);
|
pinMode(buttonNext, INPUT);
|
||||||
|
|
||||||
u8g2.begin();
|
u8g2.begin();
|
||||||
u8g2.clearBuffer();
|
u8g2.clearBuffer();
|
||||||
@@ -39,12 +29,11 @@ void loop(){
|
|||||||
const unsigned long now = millis();
|
const unsigned long now = millis();
|
||||||
carousel.update(now);
|
carousel.update(now);
|
||||||
|
|
||||||
const int currentButtonState = digitalRead(buttonOne);
|
const int currentButtonState = digitalRead(buttonNext);
|
||||||
if (lastButtonState == LOW && currentButtonState == HIGH) {
|
if (lastButtonNextState == LOW && currentButtonState == HIGH) {
|
||||||
number += 10;
|
|
||||||
carousel.nextScreen();
|
carousel.nextScreen();
|
||||||
}
|
}
|
||||||
lastButtonState = currentButtonState;
|
lastButtonNextState = currentButtonState;
|
||||||
|
|
||||||
if (carousel.consumeDirty()) {
|
if (carousel.consumeDirty()) {
|
||||||
u8g2.clearBuffer();
|
u8g2.clearBuffer();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user