This repository was archived by the owner on Dec 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
changeLabelVisible()
Mammad900 edited this page Aug 31, 2020
·
1 revision
Makes a label visible or hidden.
- Page (
int) : The number of the page which contains the label - Index (
int) : Index of the label relative to it's containing page. - Value (
bool) : If true, the label will become visible; if false, the label will become hidden.
Nothing
#define PAGE_FIRST 0
void setup(){
Serial.begin(9600);
delay(1000); // Give time for serial communication to start.
int waitLabel = addlabel(PAGE_FIRST, 0, 10, F("Open serial monitor on your computer first."),
TFT_WHITE, &FreeSans9pt7b, 1, 1, true, !Serial); // Only shown if serial communication is inactive.
int helpLabel = addlabel(PAGE_FIRST, 0, 100, F("Enter any number to show it's cube root here."),
TFT_WHITE, &FreeSans9pt7b, 1, 1, Serial); // If serial communication is active, Serial evaluates to true and the label is enabled. If it is inactive, the label is disabled.
int resultLabel= addlabel(PAGE_FIRST, 0, 260, "", TFT_WHITE, &FreeBigFont);
if(!Serial){
while(!Serial);
changeLabelVisible(PAGE_MAIN,waitLabel,false); // Hide 'Open serial monitor on your computer first.'
changeLabelEnabled(PAGE_MAIN,helpLabel,true); // Enable the label
}
}
void loop(){
if(Serial.available()>0){
delay(100); // Wait for the message to receive
int number = Serial.parseInt(); // Read the message from serial buffer
float cubeRoot = cbrt(number); // Calculate cube root
changeLabelText(PAGE_MAIN,resultLabel,String(cubeRoot));
}
}In startup, the labels are disabled and a message is shown until serial monitor is opened. Then displays the cube root of any number entered in serial monitor.
void changeLabelVisible(int page, int i, bool val) {
if (label_visible[page][i] != val) {
HCT
label_visible[page][i] = val;
if (CurrentPage == page) {
if (val) {
drawlabel(page, i);
}
else {
undrawlabel(page, i);
}
}
}
}Note: HCT is a macro for making the rest of the library aware that something has changed.