Skip to content
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

Adding touch control to change the display brightness #1

Open
wants to merge 1 commit 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
12 changes: 9 additions & 3 deletions mariobros-clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Clockface.h"
#include "WiFiConnect.h"
#include "CWDateTime.h"
#include "touch.h"

MatrixPanel_I2S_DMA *dma_display = nullptr;
WiFiConnect wifi;
Expand All @@ -12,8 +13,6 @@ uint16_t myBLACK = dma_display->color565(0, 0, 0);
uint16_t myWHITE = dma_display->color565(255, 255, 255);
uint16_t myBLUE = dma_display->color565(0, 0, 255);

byte displayBright = 32;

void displaySetup() {
HUB75_I2S_CFG mxconfig(
64, // module width
Expand Down Expand Up @@ -52,9 +51,16 @@ void setup() {
cwDateTime.begin();

clockface->setup(&cwDateTime);

// For touch code to update
matrixDisplay = dma_display;

// Adding interupts to the Trinity Touchpads
touchAttachInterrupt(T8, gotTouch8, threshold);
touchAttachInterrupt(T9, gotTouch9, threshold);
}

void loop() {
clockface->update();

processTouch();
}
44 changes: 44 additions & 0 deletions touch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
uint8_t displayBright = 32;
uint8_t brightnessChangeSteps = 4;

int threshold = 40; //This is a decent value from testing
bool touch8detected = false;
bool touch9detected = false;

MatrixPanel_I2S_DMA *matrixDisplay;

// We will change the brightness in the loop rather than the interupts
void gotTouch8() {
touch8detected = true;
}

void gotTouch9() {
touch9detected = true;
}

void processTouch() {
if (touch8detected) {
//Bright up
touch8detected = false;
//Serial.println("Touch 8 detected");
if (displayBright > 255 - brightnessChangeSteps) {
displayBright = 255;
} else {
displayBright = displayBright + brightnessChangeSteps;
}
matrixDisplay->setBrightness8(displayBright);
}
if (touch9detected) {
//Bright down
touch9detected = false;
//Serial.println("Touch 9 detected");

if (displayBright <= brightnessChangeSteps) {
displayBright = brightnessChangeSteps;
//1 seems to be off, so no point being that low
} else {
displayBright = displayBright - brightnessChangeSteps;
}
matrixDisplay->setBrightness8(displayBright);
}
}