Skip to content

Add drop down menu for LED pin #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/Uhr.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ struct GLOBAL {
bool bootShowWifi;
bool bootShowIP;

uint8_t LEDpin;
uint8_t powerButton;
uint8_t modeButton;
uint8_t speedButton;

Birthday birthday[MAX_BIRTHDAY_COUNT];
};
GLOBAL G = {};
Expand Down Expand Up @@ -254,6 +259,7 @@ enum CommandWords {
COMMAND_SET_AUTO_BRIGHT = 102,
COMMAND_SET_LAYOUT_VARIANT = 103,
COMMAND_SET_MQTT_HA_DISCOVERY = 104,
COMMAND_SET_GPIO = 105,

COMMAND_SPEED = 152,

Expand Down
6 changes: 6 additions & 0 deletions include/clockWork.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ class ClockWork {
uint32_t previousMillis = 0;
uint32_t lux = 0;

// Variable to store the time when the button was pressed
unsigned long buttonPressStart = 0;
// State of the button
bool buttonPressed = false;

private:
//------------------------------------------------------------------------------
// Helper Functions
//------------------------------------------------------------------------------
void loopAutoBrightLogic();
void loopGPIOinput();
uint32_t num32BitWithOnesAccordingToColumns();
bool isRomanLanguage();

Expand Down
113 changes: 107 additions & 6 deletions include/clockWork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,86 @@ void ClockWork::loopAutoBrightLogic() {

//------------------------------------------------------------------------------

void ClockWork::loopGPIOinput() {
// Read the power button state
int powerButtonState = digitalRead(G.powerButton);

// Button is pressed
if (powerButtonState == HIGH && !buttonPressed) {
buttonPressed = true; // Button is now pressed
// Set off if brightness is set, set on if brightness is 0
if (G.color[0].B > 0) {
for (uint8_t i = 0; i < 3; i++) {
G.color[i].B = 0;
}
} else {
for (uint8_t i = 0; i < 3; i++) {
G.color[i].B = 1;
}
}
}

// Read the mode button state
int modeButtonState = digitalRead(G.modeButton);

// Check if the button is pressed
if (modeButtonState == LOW && !buttonPressed) {
buttonPressed = true; // Button is now pressed
buttonPressStart = millis(); // Record the start time of the press
}

// Check if the button is released
if (modeButtonState == HIGH && buttonPressed) {
buttonPressed = false; // Button is released
unsigned long pressDuration = millis() - buttonPressStart;

if (pressDuration < 2000) { // Short press duration threshold (2000 ms)
// set next mode in range 1 - 8
G.prog = (G.prog % 8) + 1;
} else {
// set transition in range 0 - 12
G.transitionType = (G.transitionType + 1) % 13;
}
}

// Read the speed button state
int speedButtonState = digitalRead(G.speedButton);

// Check if the button is pressed
if (speedButtonState == LOW && !buttonPressed) {
buttonPressed = true; // Button is now pressed
buttonPressStart = millis(); // Record the start time of the press
}

// Check if the button is released
if (speedButtonState == HIGH && buttonPressed) {
buttonPressed = false; // Button is released
unsigned long pressDuration = millis() - buttonPressStart;

if (pressDuration < 2000) { // Short press duration threshold (2000 ms)
// Set brightness in range 10% - 100% with step 10%
if (G.color[0].B == 1) {
G.color[0].B = 0.1;
} else if (G.color[0].B >= 0.9) {
G.color[0].B = 1;
} else {
G.color[0].B += 0.1;
}
} else {
// Set hue in range 0 - 360 with step 30
if (G.color[0].H == 360) {
G.color[0].B = 0;
} else if (G.color[0].B >= 330) {
G.color[0].B = 360;
} else {
G.color[0].B += 30;
}
}
}
}

//------------------------------------------------------------------------------

iUhrType *ClockWork::getPointer(uint8_t type) {
switch (type) {
case Ger10x11:
Expand Down Expand Up @@ -185,11 +265,13 @@ void ClockWork::initLedStrip(uint8_t num) {
}
if (strip_RGBW == NULL) {
#ifdef ESP8266
strip_RGBW = new NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod>(500);
strip_RGBW =
new NeoPixelBus<NeoGrbwFeature, NeoEsp8266BitBangWs2812xMethod>(
500, G.LEDpin);
#elif defined(ESP32)
pinMode(LED_PIN, OUTPUT);
pinMode(G.LEDpin, OUTPUT);
strip_RGBW =
new NeoPixelBus<NeoGrbwFeature, NeoSk6812Method>(500, LED_PIN);
new NeoPixelBus<NeoGrbwFeature, NeoSk6812Method>(500, G.LEDpin);
#endif
strip_RGBW->Begin();
}
Expand All @@ -201,11 +283,13 @@ void ClockWork::initLedStrip(uint8_t num) {
}
if (strip_RGB == NULL) {
#ifdef ESP8266
strip_RGB = new NeoPixelBus<NeoMultiFeature, Neo800KbpsMethod>(500);
strip_RGB =
new NeoPixelBus<NeoMultiFeature,
NeoEsp8266BitBangWs2812xMethod>(500, G.LEDpin);
#elif defined(ESP32)
pinMode(LED_PIN, OUTPUT);
pinMode(G.LEDpin, OUTPUT);
strip_RGB = new NeoPixelBus<NeoMultiFeature, NeoWs2812xMethod>(
500, LED_PIN);
500, G.LEDpin);
#endif
strip_RGB->Begin();
}
Expand Down Expand Up @@ -1416,6 +1500,23 @@ void ClockWork::loop(struct tm &tm) {
break;
}

case COMMAND_SET_GPIO: {
led.clear();

// Print new types
Serial.printf("Clock LED pin: GPIO%u\n", G.LEDpin);
Serial.printf("Clock power button: GPIO%u\n", G.powerButton);
Serial.printf("Clock mode button: GPIO%u\n", G.modeButton);
Serial.printf("Clock speed button: GPIO%u\n", G.speedButton);

eeprom::write();
initLedStrip(G.Colortype);

clearClockByProgInit();
parametersChanged = true;
break;
}

case COMMAND_SET_COLORTYPE: {
// G.param1 sets new Colortype
Serial.printf("LED Colortype: %u\n", G.param1);
Expand Down
3 changes: 3 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// PIN Configuration
//--------------------------------------------------------------------------
#define LED_PIN 3 // Use direct pin number
#define POWER_BUTTON 2 // Use direct pin number
#define MODE_BUTTON 13 // Use direct pin number
#define SPEED_BUTTON 14 // Use direct pin number
#define SDA_PIN_ESP32 21 // Use direct pin number
#define SCL_PIN_ESP32 22 // Use direct pin number

Expand Down
12 changes: 12 additions & 0 deletions include/webPageAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,18 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload,

//------------------------------------------------------------------------------

case COMMAND_SET_GPIO: {
G.progInit = true;

G.LEDpin = split(payload, 3);
G.powerButton = split(payload, 6);
G.modeButton = split(payload, 9);
G.speedButton = split(payload, 12);
break;
}

//------------------------------------------------------------------------------

case COMMAND_SET_BIRTHDAYS: {

for (uint8_t i = 0; i < MAX_BIRTHDAY_COUNT; i++) {
Expand Down
12 changes: 10 additions & 2 deletions src/Wortuhr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ iUhrType *usedUhrType = nullptr;
#include "NeoMultiFeature.hpp"

#ifdef ESP8266
NeoPixelBus<NeoMultiFeature, Neo800KbpsMethod> *strip_RGB = NULL;
NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *strip_RGBW = NULL;
NeoPixelBus<NeoMultiFeature, NeoEsp8266BitBangWs2812xMethod> *strip_RGB = NULL;
NeoPixelBus<NeoGrbwFeature, NeoEsp8266BitBangWs2812xMethod> *strip_RGBW = NULL;
#elif defined(ESP32)
NeoPixelBus<NeoGrbwFeature, NeoSk6812Method> *strip_RGBW = NULL;
NeoPixelBus<NeoMultiFeature, NeoWs2812xMethod> *strip_RGB = NULL;
Expand Down Expand Up @@ -159,6 +159,9 @@ void setup() {
//-------------------------------------
#if GENERAL_VERBOSE
Serial.begin(115200);
pinMode(G.powerButton, INPUT_PULLUP);
pinMode(G.modeButton, INPUT_PULLUP);
pinMode(G.speedButton, INPUT_PULLUP);
Serial.println("");
Serial.println("--------------------------------------");
Serial.println("Begin Setup");
Expand Down Expand Up @@ -272,6 +275,11 @@ void setup() {
G.transitionColorize = 0;
G.transitionDemo = false;

G.LEDpin = LED_PIN;
G.powerButton = POWER_BUTTON;
G.modeButton = MODE_BUTTON;
G.speedButton = SPEED_BUTTON;

for (uint8_t i = 0; i < MAX_BIRTHDAY_COUNT; i++) {
G.birthday[i].day = 1;
G.birthday[i].month = 1;
Expand Down
80 changes: 80 additions & 0 deletions webpage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,86 @@ <h2 data-i18next="settings.status.h2"></h2>
</form>
</div>

<div class="box">
<h2 data-i18next="settings.hardware-config.h2"></h2>
<form class="pure-form pure-form-aligned">
<fieldset>
<div class="pure-control-group">
<legend data-i18next="settings.hardware-config.help"></legend>
<label for="ledpin" data-i18next="settings.hardware-config.led-pin"></label><select name="ledpin" id="ledpin" size="1">
<option value="2" data-i18next="settings.hardware-config.GPIO2"></option>
<option value="3" data-i18next="settings.hardware-config.GPIO3"></option>
<option value="4" data-i18next="settings.hardware-config.GPIO4"></option>
<option value="5" data-i18next="settings.hardware-config.GPIO5"></option>
<option value="6" data-i18next="settings.hardware-config.GPIO6"></option>
<option value="7" data-i18next="settings.hardware-config.GPIO7"></option>
<option value="8" data-i18next="settings.hardware-config.GPIO8"></option>
<option value="9" data-i18next="settings.hardware-config.GPIO9"></option>
<option value="10" data-i18next="settings.hardware-config.GPIO10"></option>
<option value="13" data-i18next="settings.hardware-config.GPIO13"></option>
<option value="14" data-i18next="settings.hardware-config.GPIO14"></option>
<option value="20" data-i18next="settings.hardware-config.GPIO20"></option>
<option value="21" data-i18next="settings.hardware-config.GPIO21"></option>
</select>
</div>
<div class="pure-control-group">
<label for="powerbutton" data-i18next="settings.hardware-config.power-button"></label><select name="powerbutton" id="powerbutton" size="1">
<option value="2" data-i18next="settings.hardware-config.GPIO2"></option>
<option value="3" data-i18next="settings.hardware-config.GPIO3"></option>
<option value="4" data-i18next="settings.hardware-config.GPIO4"></option>
<option value="5" data-i18next="settings.hardware-config.GPIO5"></option>
<option value="6" data-i18next="settings.hardware-config.GPIO6"></option>
<option value="7" data-i18next="settings.hardware-config.GPIO7"></option>
<option value="8" data-i18next="settings.hardware-config.GPIO8"></option>
<option value="9" data-i18next="settings.hardware-config.GPIO9"></option>
<option value="10" data-i18next="settings.hardware-config.GPIO10"></option>
<option value="13" data-i18next="settings.hardware-config.GPIO13"></option>
<option value="14" data-i18next="settings.hardware-config.GPIO14"></option>
<option value="20" data-i18next="settings.hardware-config.GPIO20"></option>
<option value="21" data-i18next="settings.hardware-config.GPIO21"></option>
</select>
</div>
<div class="pure-control-group">
<label for="modebutton" data-i18next="settings.hardware-config.mode-button"></label><select name="modebutton" id="modebutton" size="1">
<option value="2" data-i18next="settings.hardware-config.GPIO2"></option>
<option value="3" data-i18next="settings.hardware-config.GPIO3"></option>
<option value="4" data-i18next="settings.hardware-config.GPIO4"></option>
<option value="5" data-i18next="settings.hardware-config.GPIO5"></option>
<option value="6" data-i18next="settings.hardware-config.GPIO6"></option>
<option value="7" data-i18next="settings.hardware-config.GPIO7"></option>
<option value="8" data-i18next="settings.hardware-config.GPIO8"></option>
<option value="9" data-i18next="settings.hardware-config.GPIO9"></option>
<option value="10" data-i18next="settings.hardware-config.GPIO10"></option>
<option value="13" data-i18next="settings.hardware-config.GPIO13"></option>
<option value="14" data-i18next="settings.hardware-config.GPIO14"></option>
<option value="20" data-i18next="settings.hardware-config.GPIO20"></option>
<option value="21" data-i18next="settings.hardware-config.GPIO21"></option>
</select>
</div>
<div class="pure-control-group">
<label for="speedbutton" data-i18next="settings.hardware-config.speed-button"></label><select name="speedbutton" id="speedbutton" size="1">
<option value="2" data-i18next="settings.hardware-config.GPIO2"></option>
<option value="3" data-i18next="settings.hardware-config.GPIO3"></option>
<option value="4" data-i18next="settings.hardware-config.GPIO4"></option>
<option value="5" data-i18next="settings.hardware-config.GPIO5"></option>
<option value="6" data-i18next="settings.hardware-config.GPIO6"></option>
<option value="7" data-i18next="settings.hardware-config.GPIO7"></option>
<option value="8" data-i18next="settings.hardware-config.GPIO8"></option>
<option value="9" data-i18next="settings.hardware-config.GPIO9"></option>
<option value="10" data-i18next="settings.hardware-config.GPIO10"></option>
<option value="13" data-i18next="settings.hardware-config.GPIO13"></option>
<option value="14" data-i18next="settings.hardware-config.GPIO14"></option>
<option value="20" data-i18next="settings.hardware-config.GPIO20"></option>
<option value="21" data-i18next="settings.hardware-config.GPIO21"></option>
</select>
</div>
<div class="pure-controls">
<button id="hardware-config-save-button" class="pure-button" data-i18next="settings.hardware-config.save"></button>
</div>
</fieldset>
</form>
</div>

<div class="box">
<h2 data-i18next="settings.led-type.h2"></h2>
<form class="pure-form pure-form-aligned">
Expand Down
24 changes: 24 additions & 0 deletions webpage/language/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,30 @@ let TRANSLATION_DE_DE = {
"label": "Verbindungsstatus",
"connect": "Verbinden"
},
"hardware-config": {
"h2": "Hardware Einstellung",
"help": "Hier kann der verwendete Pin für den LED-Streifen eingestellt werden.\n " +
"Hinweis: Es muss die GPIO-Nummer verwendet werden, nicht die aufgedruckte Zahl auf dem Board!\n " +
"Möglicherweise muss die Wortuhr neu gestartet werden.",
"led-pin": "LED pin",
"power-button": "Power Button",
"mode-button": "Mode Button",
"speed-button": "Speed Button",
"GPIO2": "GPIO2",
"GPIO3": "GPIO3",
"GPIO4": "GPIO4",
"GPIO5": "GPIO5",
"GPIO6": "GPIO6",
"GPIO7": "GPIO7",
"GPIO8": "GPIO8",
"GPIO9": "GPIO9",
"GPIO10": "GPIO10",
"GPIO13": "GPIO13",
"GPIO14": "GPIO14",
"GPIO20": "GPIO20",
"GPIO21": "GPIO21",
"save": "Einstellung speichern"
},
"led-type": {
"h2": "LED-Typ",
"help": "Hier können Sie den Typ des verwendeten LED-Streifens (WS2812 oder SK6812) einstellen.\n" +
Expand Down
24 changes: 24 additions & 0 deletions webpage/language/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,30 @@ let TRANSLATION_EN_US = {
"label": "Connection Status",
"connect": "Connect"
},
"hardware-config": {
"h2": "Hardware configuration",
"help": "Here you can set the pin used for the LED strip.\n " +
"Note: You need to set the GPIO pin, not the pin printed on your board!\n " +
"It may be neccessary to restart your Wordclock.",
"led-pin": "LED pin",
"power-button": "Power Button",
"mode-button": "Mode Button",
"speed-button": "Speed Button",
"GPIO2": "GPIO2",
"GPIO3": "GPIO3",
"GPIO4": "GPIO4",
"GPIO5": "GPIO5",
"GPIO6": "GPIO6",
"GPIO7": "GPIO7",
"GPIO8": "GPIO8",
"GPIO9": "GPIO9",
"GPIO10": "GPIO10",
"GPIO13": "GPIO13",
"GPIO14": "GPIO14",
"GPIO20": "GPIO20",
"GPIO21": "GPIO21",
"save": "Save Setting"
},
"led-type": {
"h2": "LED Type",
"help": "Here you can set the type of LED strip used (WS2812 or SK6812).\n " +
Expand Down
Loading