Skip to content
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: 6 additions & 6 deletions examples/Advanced/DashboardUI/DashboardUI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ void update_time_and_date()
void update_button_events()
{
/* If button clicked, log out */
if (M5StamPLC.BtnA.wasClicked()) {
if (M5StamPLC.BtnA().wasClicked()) {
dashboard_ui.console_log("BtnA click");
}
if (M5StamPLC.BtnB.wasClicked()) {
if (M5StamPLC.BtnB().wasClicked()) {
dashboard_ui.console_log("BtnB click");
}
if (M5StamPLC.BtnC.wasClicked()) {
if (M5StamPLC.BtnC().wasClicked()) {
dashboard_ui.console_log("BtnC click");
}

/* Play button press and release tone */
if (M5StamPLC.BtnA.wasPressed() || M5StamPLC.BtnB.wasPressed() || M5StamPLC.BtnC.wasPressed()) {
if (M5StamPLC.BtnA().wasPressed() || M5StamPLC.BtnB().wasPressed() || M5StamPLC.BtnC().wasPressed()) {
M5StamPLC.tone(600, 20);
} else if (M5StamPLC.BtnA.wasReleased() || M5StamPLC.BtnB.wasReleased() || M5StamPLC.BtnC.wasReleased()) {
} else if (M5StamPLC.BtnA().wasReleased() || M5StamPLC.BtnB().wasReleased() || M5StamPLC.BtnC().wasReleased()) {
M5StamPLC.tone(800, 20);
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ void setup()
M5StamPLC.begin();

/* Init dashboard UI */
dashboard_ui.init(&M5StamPLC.Display);
dashboard_ui.init(&M5StamPLC.Display());

/* Create a task to write relay regularly */
xTaskCreate(task_write_relay_regularly, "relay", 2048, NULL, 15, NULL);
Expand Down
20 changes: 10 additions & 10 deletions examples/Basic/Button/Button.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ void setup()
/* Init M5StamPLC */
M5StamPLC.begin();

M5StamPLC.Display.setTextScroll(true);
M5StamPLC.Display.setTextColor(TFT_GREENYELLOW);
M5StamPLC.Display.println("Button example");
M5StamPLC.Display.setTextColor(TFT_YELLOW);
M5StamPLC.Display().setTextScroll(true);
M5StamPLC.Display().setTextColor(TFT_GREENYELLOW);
M5StamPLC.Display().println("Button example");
M5StamPLC.Display().setTextColor(TFT_YELLOW);
}

void loop()
Expand All @@ -23,12 +23,12 @@ void loop()
M5StamPLC.update();

/* Check if button was clicked */
if (M5StamPLC.BtnA.wasClicked()) {
M5StamPLC.Display.println("Button A was clicked");
} else if (M5StamPLC.BtnB.wasClicked()) {
M5StamPLC.Display.println("Button B was clicked");
} else if (M5StamPLC.BtnC.wasClicked()) {
M5StamPLC.Display.println("Button C was clicked");
if (M5StamPLC.BtnA().wasClicked()) {
M5StamPLC.Display().println("Button A was clicked");
} else if (M5StamPLC.BtnB().wasClicked()) {
M5StamPLC.Display().println("Button B was clicked");
} else if (M5StamPLC.BtnC().wasClicked()) {
M5StamPLC.Display().println("Button C was clicked");
}

delay(100);
Expand Down
6 changes: 3 additions & 3 deletions examples/Basic/Buzzer/Buzzer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ void loop()
M5StamPLC.update();

/* Play tone if button was clicked */
if (M5StamPLC.BtnA.wasClicked()) {
if (M5StamPLC.BtnA().wasClicked()) {
M5StamPLC.tone(523, 50);
}
if (M5StamPLC.BtnB.wasClicked()) {
if (M5StamPLC.BtnB().wasClicked()) {
M5StamPLC.tone(659, 50);
}
if (M5StamPLC.BtnC.wasClicked()) {
if (M5StamPLC.BtnC().wasClicked()) {
M5StamPLC.tone(880, 50);
}

Expand Down
38 changes: 19 additions & 19 deletions examples/Basic/Display/Display.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@ void setup()
void loop()
{
/* Fill screen with colors */
M5StamPLC.Display.fillScreen(TFT_WHITE);
M5StamPLC.Display().fillScreen(TFT_WHITE);
delay(800);
M5StamPLC.Display.fillScreen(TFT_RED);
M5StamPLC.Display().fillScreen(TFT_RED);
delay(800);
M5StamPLC.Display.fillScreen(TFT_GREEN);
M5StamPLC.Display().fillScreen(TFT_GREEN);
delay(800);
M5StamPLC.Display.fillScreen(TFT_BLUE);
M5StamPLC.Display().fillScreen(TFT_BLUE);
delay(800);
M5StamPLC.Display.fillScreen(TFT_BLACK);
M5StamPLC.Display().fillScreen(TFT_BLACK);
delay(800);

/* Set cursor and print text */
M5StamPLC.Display.setCursor(10, 10);
M5StamPLC.Display.setTextColor(TFT_WHITE);
M5StamPLC.Display.setTextSize(1);
M5StamPLC.Display.printf("Display Test!");
M5StamPLC.Display().setCursor(10, 10);
M5StamPLC.Display().setTextColor(TFT_WHITE);
M5StamPLC.Display().setTextSize(1);
M5StamPLC.Display().printf("Display Test!");
delay(800);

/* Draw shapes */
M5StamPLC.Display.drawRect(100, 50, 50, 50, BLUE);
M5StamPLC.Display().drawRect(100, 50, 50, 50, BLUE);
delay(800);
M5StamPLC.Display.fillRect(100, 50, 50, 50, BLUE);
M5StamPLC.Display().fillRect(100, 50, 50, 50, BLUE);
delay(800);
M5StamPLC.Display.drawCircle(100, 50, 50, RED);
M5StamPLC.Display().drawCircle(100, 50, 50, RED);
delay(800);
M5StamPLC.Display.fillCircle(100, 50, 50, RED);
M5StamPLC.Display().fillCircle(100, 50, 50, RED);
delay(800);
M5StamPLC.Display.drawTriangle(30, 30, 180, 50, 80, 100, YELLOW);
M5StamPLC.Display().drawTriangle(30, 30, 180, 50, 80, 100, YELLOW);
delay(800);
M5StamPLC.Display.fillTriangle(30, 30, 180, 50, 80, 100, YELLOW);
M5StamPLC.Display().fillTriangle(30, 30, 180, 50, 80, 100, YELLOW);
delay(800);

/* Draw random triangles */
for (int i = 0; i < 1000; i++) {
M5StamPLC.Display.fillTriangle(random(M5StamPLC.Display.width() - 1), random(M5StamPLC.Display.height() - 1),
random(M5StamPLC.Display.width() - 1), random(M5StamPLC.Display.height() - 1),
random(M5StamPLC.Display.width() - 1), random(M5StamPLC.Display.height() - 1),
random(0xfffe));
M5StamPLC.Display().fillTriangle(
random(M5StamPLC.Display().width() - 1), random(M5StamPLC.Display().height() - 1),
random(M5StamPLC.Display().width() - 1), random(M5StamPLC.Display().height() - 1),
random(M5StamPLC.Display().width() - 1), random(M5StamPLC.Display().height() - 1), random(0xfffe));
}
delay(800);
}
10 changes: 5 additions & 5 deletions examples/Modules/StamPLC_IO/GetStatus/GetStatus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include <Arduino.h>
#include <M5StamPLC.h>

M5Canvas canvas(&M5StamPLC.Display);
M5Canvas canvas(&M5StamPLC.Display());
M5StamPLC_IO stamplc_io;

void setup()
{
M5StamPLC.begin();
canvas.createSprite(M5StamPLC.Display.width(), M5StamPLC.Display.height());
canvas.createSprite(M5StamPLC.Display().width(), M5StamPLC.Display().height());
canvas.setTextScroll(true);
canvas.fillScreen(TFT_BLACK);
canvas.setTextSize(1);
Expand Down Expand Up @@ -48,7 +48,7 @@ void setup()
canvas.setTextColor(TFT_YELLOW);
canvas.println("press BtnC to start monitoring");
canvas.pushSprite(0, 0);
while (!M5StamPLC.BtnC.isPressed()) {
while (!M5StamPLC.BtnC().isPressed()) {
M5StamPLC.update();
delay(10);
}
Expand Down Expand Up @@ -90,8 +90,8 @@ void loop()
canvas.printf("System: %s\n", sys_status == 0 ? "Normal" : "Error");
}

if (M5StamPLC.BtnA.wasClicked()) stamplc_io.toggleIOBit(M5StamPLC_IO::BIT_CH1_PU_EN);
if (M5StamPLC.BtnB.wasClicked()) stamplc_io.toggleIOBit(M5StamPLC_IO::BIT_CH2_PU_EN);
if (M5StamPLC.BtnA().wasClicked()) stamplc_io.toggleIOBit(M5StamPLC_IO::BIT_CH1_PU_EN);
if (M5StamPLC.BtnB().wasClicked()) stamplc_io.toggleIOBit(M5StamPLC_IO::BIT_CH2_PU_EN);

if (stamplc_io.syncAddress()) {
canvas.printf("Address changed to 0x%02X\n", stamplc_io.getCurrentAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ void onAddrChange(uint8_t old_addr, uint8_t new_addr)

void updateDisplay()
{
M5StamPLC.Display.fillScreen(TFT_BLACK);
M5StamPLC.Display.setCursor(0, 0);
M5StamPLC.Display().fillScreen(TFT_BLACK);
M5StamPLC.Display().setCursor(0, 0);

M5StamPLC.Display.setTextColor(TFT_GREENYELLOW);
M5StamPLC.Display.println("== Multi IO HotPlug ==");
M5StamPLC.Display().setTextColor(TFT_GREENYELLOW);
M5StamPLC.Display().println("== Multi IO HotPlug ==");

M5StamPLC.Display.setTextColor(TFT_CYAN);
M5StamPLC.Display.printf("Online: %d\n\n", io_mgr.count());
M5StamPLC.Display().setTextColor(TFT_CYAN);
M5StamPLC.Display().printf("Online: %d\n\n", io_mgr.count());

for (uint8_t i = 0; i < io_mgr.count() && i < 6; i++) {
M5StamPLC_IO* dev = io_mgr.get(i);
uint8_t addr = dev->getCurrentAddress();
M5StamPLC.Display.setTextColor(TFT_GREEN);
M5StamPLC.Display.printf("0x%02X FW:0x%02X", addr, dev->getFirmwareVersion());
M5StamPLC.Display.setTextColor(TFT_YELLOW);
M5StamPLC.Display.printf(" DIP:0x%02X\n", dev->getExpectedAddress());
M5StamPLC.Display().setTextColor(TFT_GREEN);
M5StamPLC.Display().printf("0x%02X FW:0x%02X", addr, dev->getFirmwareVersion());
M5StamPLC.Display().setTextColor(TFT_YELLOW);
M5StamPLC.Display().printf(" DIP:0x%02X\n", dev->getExpectedAddress());
}
}

void setup()
{
M5StamPLC.begin();
M5StamPLC.Display.setTextScroll(false);
M5StamPLC.Display.setTextSize(1);
M5StamPLC.Display.setFont(&fonts::efontCN_16);
M5StamPLC.Display().setTextScroll(false);
M5StamPLC.Display().setTextSize(1);
M5StamPLC.Display().setFont(&fonts::efontCN_16);

Serial.begin(115200);
Serial.println("\n=== M5StamPLC IO Multi-Device Hot-Plug ===");
Expand Down
52 changes: 26 additions & 26 deletions examples/Modules/StamPLC_IO/PWM_Control/PWM_Control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ bool btnC_longPressed = false;

void updateDisplay()
{
M5StamPLC.Display.fillScreen(TFT_BLACK);
M5StamPLC.Display.setCursor(0, 0);
M5StamPLC.Display().fillScreen(TFT_BLACK);
M5StamPLC.Display().setCursor(0, 0);

M5StamPLC.Display.setTextColor(TFT_GREENYELLOW);
M5StamPLC.Display.println("=== PWM Control ===");
M5StamPLC.Display().setTextColor(TFT_GREENYELLOW);
M5StamPLC.Display().println("=== PWM Control ===");

M5StamPLC.Display.setTextColor(TFT_CYAN);
M5StamPLC.Display.printf("Mode: %s Freq: %dHz\n", pwm_mode ? "PWM" : "IO", pwm_freq);
M5StamPLC.Display().setTextColor(TFT_CYAN);
M5StamPLC.Display().printf("Mode: %s Freq: %dHz\n", pwm_mode ? "PWM" : "IO", pwm_freq);

M5StamPLC.Display.setTextColor(TFT_YELLOW);
M5StamPLC.Display.printf("CH1: %d.%d%% (%d/1000)\n", ch1_duty / 10, ch1_duty % 10, ch1_duty);
M5StamPLC.Display.printf("CH2: %d.%d%% (%d/1000)\n", ch2_duty / 10, ch2_duty % 10, ch2_duty);
M5StamPLC.Display().setTextColor(TFT_YELLOW);
M5StamPLC.Display().printf("CH1: %d.%d%% (%d/1000)\n", ch1_duty / 10, ch1_duty % 10, ch1_duty);
M5StamPLC.Display().printf("CH2: %d.%d%% (%d/1000)\n", ch2_duty / 10, ch2_duty % 10, ch2_duty);

M5StamPLC.Display.setTextColor(TFT_DARKGREY);
M5StamPLC.Display.println("A: Toggle PWM mode");
M5StamPLC.Display.println("B/C: duty+ Long: duty-");
M5StamPLC.Display().setTextColor(TFT_DARKGREY);
M5StamPLC.Display().println("A: Toggle PWM mode");
M5StamPLC.Display().println("B/C: duty+ Long: duty-");
}

void setup()
{
M5StamPLC.begin();
M5StamPLC.Display.setTextScroll(false);
M5StamPLC.Display.setTextSize(1);
M5StamPLC.Display.setFont(&fonts::efontCN_16);
M5StamPLC.Display.println("Try to find M5StamPLC IO module...");
M5StamPLC.Display().setTextScroll(false);
M5StamPLC.Display().setTextSize(1);
M5StamPLC.Display().setFont(&fonts::efontCN_16);
M5StamPLC.Display().println("Try to find M5StamPLC IO module...");

while (!stamplc_io.begin()) {
M5StamPLC.Display.println("Not found, retry in 1s...");
M5StamPLC.Display().println("Not found, retry in 1s...");
delay(1000);
}

M5StamPLC.Display.printf("Found: 0x%02X FW: 0x%02X\n", stamplc_io.getCurrentAddress(),
stamplc_io.getFirmwareVersion());
M5StamPLC.Display().printf("Found: 0x%02X FW: 0x%02X\n", stamplc_io.getCurrentAddress(),
stamplc_io.getFirmwareVersion());

pwm_mode = stamplc_io.getPWMMode();
pwm_freq = stamplc_io.getPWMFrequency();
Expand All @@ -78,35 +78,35 @@ void loop()

bool needUpdate = false;

if (M5StamPLC.BtnA.wasClicked()) {
if (M5StamPLC.BtnA().wasClicked()) {
pwm_mode = !pwm_mode;
stamplc_io.setPWMMode(pwm_mode);
needUpdate = true;
}

if (M5StamPLC.BtnB.wasClicked()) {
if (M5StamPLC.BtnB().wasClicked()) {
ch1_duty = (ch1_duty + 100 > 1000) ? 1000 : ch1_duty + 100;
stamplc_io.setChannelDuty(1, ch1_duty);
needUpdate = true;
} else if (M5StamPLC.BtnB.pressedFor(500) && !btnB_longPressed) {
} else if (M5StamPLC.BtnB().pressedFor(500) && !btnB_longPressed) {
btnB_longPressed = true;
ch1_duty = (ch1_duty >= 100) ? ch1_duty - 100 : 0;
stamplc_io.setChannelDuty(1, ch1_duty);
needUpdate = true;
} else if (!M5StamPLC.BtnB.isPressed()) {
} else if (!M5StamPLC.BtnB().isPressed()) {
btnB_longPressed = false;
}

if (M5StamPLC.BtnC.wasClicked()) {
if (M5StamPLC.BtnC().wasClicked()) {
ch2_duty = (ch2_duty + 100 > 1000) ? 1000 : ch2_duty + 100;
stamplc_io.setChannelDuty(2, ch2_duty);
needUpdate = true;
} else if (M5StamPLC.BtnC.pressedFor(500) && !btnC_longPressed) {
} else if (M5StamPLC.BtnC().pressedFor(500) && !btnC_longPressed) {
btnC_longPressed = true;
ch2_duty = (ch2_duty >= 100) ? ch2_duty - 100 : 0;
stamplc_io.setChannelDuty(2, ch2_duty);
needUpdate = true;
} else if (!M5StamPLC.BtnC.isPressed()) {
} else if (!M5StamPLC.BtnC().isPressed()) {
btnC_longPressed = false;
}

Expand Down
Loading
Loading