Skip to content

Instantly share code, notes, and snippets.

@hn3000
Last active June 20, 2021 08:42
Show Gist options
  • Save hn3000/221c9ef0418bd2c865302ff49e8b9202 to your computer and use it in GitHub Desktop.
Save hn3000/221c9ef0418bd2c865302ff49e8b9202 to your computer and use it in GitHub Desktop.
sqfmi Watchy button test printing over serial

A little Arduino program for the sqfmi Watchy (watchy.sqfmi.com) that makes it easy to test the buttons.

Thanks to the people on discord, especially @mayanki (who pointed me at things) and @aliceafterall who created a version of this that only uses the Watchy display (but is a bit slower because of that).

Create a new sketch in Arduino, select ESP32 Dev module as target, connect watchy, select the correct port and upload!

Output on serial (switch to 115200 Bd) looks like this:

____: no button pressed
x___: menu button pressed
_x__: back button pressed
__x_: up button pressed
___x: down button pressed

(multiple x -- multiple buttons pressed)

__x_
____
__x_
____
___x
____
x___
____
_x__
____
_x__
____

As you can see, I tried all the buttons, and they all kinda work -- but that _x__ (for the back button) only appears when I press quite hard.

Button presses are shown quite quickly, and sometimes a single press will generate multiple lines because the buttons are not debounced -- which is on purpose, I wanted to see how good or bad the buttons are.

// Watchy button testing mode over serial, inspired by script by @aliceafterall from discord
//
// https://discord.com/channels/804832182006579270/804834557412900885/854173468882501642
// https://discord.com/channels/804832182006579270/804834557412900885/854011798730702868
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
const int CS = 5;
const int DC = 10;
const int RESET = 9;
const int PIN_BUSY = 19;
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(CS, DC, RESET, PIN_BUSY));
struct Btn {
const uint8_t pin;
bool pressed;
bool last;
};
Btn menu = {26, false};
Btn back = {25, false};
Btn up = {32, false};
Btn down = {4, false};
Btn* all [] = {
&menu,
&back,
&up,
&down
};
void setup() {
display.init(0, true);
display.setFullWindow();
display.fillScreen(GxEPD_WHITE);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(40, 110);
display.print("BUTTON TEST");
display.setCursor(25, 130);
display.print("look at serial");
display.display();
for (int i = 0; i < sizeof(all) / sizeof(all[0]); ++i) {
pinMode(all[i]->pin, INPUT);
}
for (int i = 0; i < sizeof(all) / sizeof(all[0]); ++i) {
all[i]->pressed = digitalRead(all[i]->pin);
all[i]->last = all[i]->pressed;
}
Serial.begin(115200);
Serial.println("____: no button pressed");
Serial.println("x___: menu button pressed");
Serial.println("_x__: back button pressed");
Serial.println("__x_: up button pressed");
Serial.println("___x: down button pressed");
Serial.println("");
Serial.println("(multiple x -- multiple buttons pressed)");
Serial.println("");
}
void loop() {
for (int i = 0; i < sizeof(all) / sizeof(all[0]); ++i) {
all[i]->pressed = digitalRead(all[i]->pin);
}
bool changed = false;
for (int i = 0; i < sizeof(all) / sizeof(all[0]); ++i) {
if (all[i]->last != all[i]->pressed) {
changed = true;
}
all[i]->last = all[i]->pressed;
}
if (changed) {
char buf[80];
sprintf(
buf,
"%s%s%s%s\r\n",
(menu.pressed ? "x" : "_"),
(back.pressed ? "x" : "_"),
(up.pressed ? "x" : "_"),
(down.pressed ? "x" : "_")
);
Serial.print(buf);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment