Manual Control Buttons - teamias/SolarProject GitHub Wiki
Purpose
Physical buttons were added next to the screen for manual control, in the case that the screen malfunctioned or was difficult to use. The buttons allow the same functionality as the screen interface, and can be used simultaneously with the digital interface.
Design
The manual control buttons are located to the right of the digital screen. There are four buttons in total: UP, DOWN, ENTER, and EMERGENCY STOP.
The UP, DOWN, and ENTER buttons are directly on the right-hand side of the screen, and allow the user to highlight different parts of the screen to manipulate. These buttons were created for general use; that is, to minimize the number of buttons for the most versatile use, such as the addition of features and digital buttons in the future.
The EMERGENCY STOP button is placed in the upper right-hand corner of the faceplate for easy access in the case of an emergency.
[insert pic]
Code
Declaration
string currentButton = "";
bool barEntered = false;
const int buttonUp = 53;
const int buttonDown = 51;
const int buttonEnter = 49;
const int buttonEmergency = A11;
At the top of the SolarProject.ino file, the buttons and there corresponding pins are declared. Two additional global variables are declared; currentButton indicates the current button on manual control (UP, DOWN, ENTER, or EMERGENCY), and barEntered holds the true or false value that the bar has been selected for manipulation.
Initialization
pinMode(buttonUp, INPUT);
pinMode(buttonDown, INPUT);
pinMode(buttonEnter, INPUT);
pinMode(buttonEmergency, INPUT);
In the setup function, the pins corresponding to the buttons are set to pin mode INPUT.
Highlight function
The highlight function "highlights" the current button. [Insert pics of code functioning]
void highlight() {
if(currentButton == "START") {
tft.drawRect(10, 160, 100, 30, BLACK);
tft.setCursor(10 + buttonPadding, 160 + buttonPadding);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print("Start");
}
else if(currentButton == "STOP") {
tft.drawRect(10, 200, 100, 30, BLACK);
tft.setCursor(10 + buttonPadding, 200 + buttonPadding);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print("Stop");
}
else { //currentButton == "BAR"
tft.fillRect(timeBox, Y, BOXSIZE, tft.height() - Y, BLACK);
//tft.fillRect(timeBox, 0, BOXSIZE, Y + 1, PASTELGREEN);
}
}
Solar function
In the solar function, there are three digital functions: the start button, stop button, and time bar. Please see the Phases page for reference.
Initial Phase
currentButton = "START";
highlight();
Sets currentButton to START and highlights START.
Wait Phase
In the wait phase, only the start button and bar are given functionality.
if(currentButton == "START") {
if(digitalRead(buttonDown) == HIGH) {
currentButton = "BAR";
highlight();
}
If the down button is pressed, the currentButton is switched to BAR and is highlighted.
else if(digitalRead(buttonEnter) == HIGH) {
Y = 140;
tft.fillRect(timeBox, Y, BOXSIZE, tft.height() - Y, WHITE);
tft.fillRect(timeBox, 0, BOXSIZE, Y + 1, PASTELGREEN);
solarTime = tft.height() - Y;
nextPosition = Y;
createInterface(solarTime);
start = true;
startButton();
}
}
And if the enter button is pressed, start is set to true and the startButton function is called to select the start button.
else if(currentButton == "BAR") {
if(barEntered) {
if(digitalRead(buttonUp) == HIGH) {
tft.fillRect(timeBox, Y, BOXSIZE, tft.height() - Y, WHITE);
tft.fillRect(timeBox, 0, BOXSIZE, Y + 1, PASTELGREEN);
++solarTime;
--nextPosition;
createInterface(solarTime);
}
else if(digitalRead(buttonDown) == HIGH) {
tft.fillRect(timeBox, Y, BOXSIZE, tft.height() - Y, WHITE);
tft.fillRect(timeBox, 0, BOXSIZE, Y + 1, PASTELGREEN);
--solarTime;
++nextPosition;
createInterface(solarTime);
}
else { //digitalRead(buttonEnter) == HIGH
barEntered = false;
}
}
When barEntered is true, that is the user selects the bar by pressing enter, the bar enters editing mode. In editing mode, the user can manipulate the time by pressing the up button to increase the time, the down button to decrease the time, or the enter button to finalize the time and exit editing mode. The user can then return to highlighting the options of the start button or the time bar.
else { bar not entered
if(digitalRead(buttonEnter) == HIGH) {
barEntered = true;
}
else if(digitalRead(buttonUp) == HIGH) {
currentButton = "START";
highlight();
}
}
}
Execute Phase
currentButton = "STOP";
highlight();
if(digitalRead(buttonEnter) == HIGH) {
start = false;
stopButton();
}
During the execute phase, only the stop button is given functionality. Thus, currentButton is set to STOP and highlighted. If the enter button is pressed, the bool start is set to false, and the stopButton function is called to select the stop button.
Pause Phase
currentButton = "START";
highlight();
if(digitalRead(buttonEnter) == HIGH) {
start = true;
startButton();
}
During the pause phase, only the start button is given functionality. Thus, currentButton is set to START and highlighted. If the enter button is pressed, the bool start is set to true, and the startButton function is called to select the start button.
Errors to be Fixed
Digital functions need to reflect manual actions (eg touching the start button should set currentButton to start as well). When start is pressed in the wait phase, the current time should be used (to reflect any digital changes). Is there a default time set? Un-highlight buttons when the currentButton is changed (?)