Files
TTGO_TWatch_Library/examples/UserButton/UserButton.ino
2019-08-15 18:19:21 +08:00

42 lines
930 B
C++

#include <TTGO.h>
TTGOClass *ttgo;
void pressed()
{
uint16_t color = random(0xFFFF);
ttgo->eTFT->fillScreen(color);
ttgo->eTFT->setTextColor(color, TFT_WHITE);
ttgo->eTFT->drawString("User Button pressed", 5, 100, 4);
}
void released()
{
uint16_t color = random(0xFFFF);
ttgo->eTFT->fillScreen(color);
ttgo->eTFT->setTextColor(color, TFT_WHITE);
ttgo->eTFT->drawString("User Button released", 5, 100, 4);
}
void setup()
{
Serial.begin(115200);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
ttgo->eTFT->fillScreen(TFT_BLACK);
ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK);
ttgo->eTFT->setTextFont(4);
ttgo->eTFT->drawString("User Button released", 5, 100, 4);
ttgo->button->setPressedHandler(pressed);
ttgo->button->setReleasedHandler(released);
}
void loop()
{
ttgo->button->loop();
}