@eggplant @nenik So we got the buttons working so then we tried to implement a back button and the only thing i could think of doing was make it all into a switch case and the back button doesn’t work. If y’all could see the reason and explain it to me that’d be great!
Here’s the code
void SelectScreenSwitch()
{
int StepNumber = 1;
//Initilaize all variables
int RectangleWidth = 99;
int RectangleHeight = 99;
int xTLOrigin = 1;
int xTLEnd = 100;
int yTLOrigin = 1;
int yTLEnd = 100;
int xTROrigin = 381;
int xTREnd = 480;
int yTROrigin = 1;
int yTREnd = 100;
int xBROrigin = 381;
int xBREnd = 480;
int yBROrigin = 141;
int yBREnd = 240;
int xBLOrigin = 1;
int xBLEnd = 100;
int yBLOrigin = 141;
int yBLEnd = 240;
//Begin the switch process
switch(StepNumber)
{
case (1):
{
//Drawing the screen buttons in all four corners
Brain.Screen.drawRectangle(xTLOrigin,yTLOrigin,RectangleWidth,RectangleHeight,color::red);
Brain.Screen.drawRectangle(xTROrigin,yTROrigin,RectangleWidth,RectangleHeight,color::yellow);
Brain.Screen.drawRectangle(xBROrigin,yBROrigin,RectangleWidth,RectangleHeight,color::blue);
Brain.Screen.drawRectangle(xBLOrigin,yBLOrigin,RectangleWidth,RectangleHeight,color::green);
while (1)
{
//Brain Screen button programming
if (Brain.Screen.pressing())
{
int Xpos = Brain.Screen.xPosition();
int Ypos = Brain.Screen.yPosition();
if ((Xpos >= xTLOrigin && Xpos <= xTLEnd) && (Ypos >= yTLOrigin && Ypos <= yTLEnd))
{
Brain.Screen.print("test");
StepNumber = 2;
//This break seems to break out of the case 1, and switch to whatever step is now there, (2). Without, I cannot get it to work.
//break;
}
else if ((Xpos >= xBLOrigin && Xpos <= xBLEnd) && (Ypos >= yBLOrigin && Ypos <= yBLEnd))//declaring if the screen is being touched within the bottom left box box
{
StepNumber = 3;
//See other comment above for why this break needs to be here. It is also found in the Easy C programs.
//break;
}
else if ((Xpos >= xBROrigin && Xpos <= xBREnd) && (Ypos >= yBROrigin && Ypos <= yBREnd))//declaring if the screen is being touched within the bottom right box box
{
StepNumber = 4;
//break;
}
else if ((Xpos >= xTROrigin && Xpos <= xTREnd) && (Ypos >= yTROrigin && Ypos <= yTREnd))//declaring if the screen is being touched within the top left box box
{
StepNumber = 5;
//break;
}
}
}
break;
}
case (2):
{
//Red side programs go here
Brain.Screen.clearScreen();
Brain.Screen.print("Top Left button was touched");
BackButton();
break;
}
case (3):
{
//Green side programs go here
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
Brain.Screen.print("Bottom Left button was touched");
break;
}
case (4):
{
//Blue side programs go here
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
Brain.Screen.print("Bottom Right was touched");
break;
}
case (5):
{
//Yellow side programs go here
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
Brain.Screen.setFont(fontType::mono20);
Brain.Screen.print("The Battery level is ");
Brain.Screen.print(Brain.Battery.capacity(percentUnits::pct));
Brain.Screen.newLine();
Brain.Screen.newLine();
Brain.Screen.print("The Battery temperature is ");
Brain.Screen.print(Brain.Battery.temperature(percentUnits::pct));
Brain.Screen.newLine();
Brain.Screen.newLine();
Brain.Screen.print("Top Right was touched");
break;
}
}
}
int main() {
SelectScreenSwitch();
}
And here’s the back button
void BackButton(){
int xBROrigin = 381;
int xBREnd = 480;
int yBROrigin = 141;
int yBREnd = 240;
int RectangleWidth = 99;
int RectangleHeight = 99;
Brain.Screen.drawRectangle(xBROrigin,yBROrigin,RectangleWidth,RectangleHeight,color::white);
while(1){
if (Brain.Screen.pressing())
{
int Xpos = Brain.Screen.xPosition();
int Ypos = Brain.Screen.yPosition();
if ((Xpos >= xBROrigin && Xpos <= xBREnd) && (Ypos >= yBROrigin && Ypos <= yBREnd))//declaring if the screen is being touched within the bottom right box
{
int StepNumber = 1;
}
}
}
}