-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36f6e97
commit 51dcc01
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
examples/Example11_clickCallback/Example11_clickCallback.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <retroTerm.h> //Include terminal library | ||
retroTerm terminal; //Create a terminal instance | ||
uint8_t button1Id = 0; //Record the button ID globally | ||
uint8_t button2Id = 0; //Record the button ID globally | ||
uint8_t button3Id = 0; //Record the button ID globally | ||
uint32_t numberOfClicks[3] = {1,1,1}; //Record the number of clicks | ||
|
||
void processClick(uint8_t widgetClicked) { | ||
if(widgetClicked == button1Id) { | ||
terminal.scroll("Button 1 click " + String(numberOfClicks[0]++)); //Print inside the scroll window | ||
} else if(widgetClicked == button2Id) { | ||
terminal.scroll("Button 2 click " + String(numberOfClicks[1]++)); //Print inside the scroll window | ||
} else if(widgetClicked == button3Id) { | ||
terminal.scroll("Button 3 click " + String(numberOfClicks[2]++)); //Print inside the scroll window | ||
} else { | ||
terminal.scroll("Unknown click"); //Print inside the scroll window | ||
} | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); //Initialise the Serial stream | ||
terminal.begin(Serial); //Initialise the library | ||
terminal.eraseScreen(); //Clear the screen | ||
terminal.hideCursor(); //Hide the terminal cursor | ||
terminal.enableMouse(); //Capture the mouse so it can be used with widgets | ||
terminal.setScrollWindow(4,12); //Set up somewhere to show the events without disrupting the button | ||
button1Id = terminal.newButton(1, 1, 15, 3, F("Button 1"), COLOUR_RED, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box | ||
button2Id = terminal.newButton(16, 1, 15, 3, F("Button 2"), COLOUR_GREEN, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box | ||
button3Id = terminal.newButton(31, 1, 15, 3, F("Button 3"), COLOUR_BLUE, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box | ||
terminal.widgetShortcutKey(button1Id,f1Pressed); //Assign a shortcut key of F1 | ||
terminal.widgetShortcutKey(button2Id,f2Pressed); //Assign a shortcut key of F2 | ||
terminal.widgetShortcutKey(button3Id,f3Pressed); //Assign a shortcut key of F3 | ||
terminal.showWidget(button1Id); //Make the button visible, all widgets start 'invisible' for later display | ||
terminal.showWidget(button2Id); //Make the button visible, all widgets start 'invisible' for later display | ||
terminal.showWidget(button3Id); //Make the button visible, all widgets start 'invisible' for later display | ||
terminal.setClickCallback(processClick); //retroTerm callback for click events | ||
} | ||
|
||
void loop() { | ||
terminal.houseKeeping(); //You MUST run housekeeping to show/detect any changes or events | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# clickCallback.ino | ||
|
||
This example sketch shows how to use the callback function to register clicks from various widgets. As you click the buttons you should get output like this. | ||
|
||
![](images/clickCallback.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.