Optimized code v01.ino

This commit is contained in:
2019-01-13 21:53:40 +00:00
parent d5d6a4bffe
commit 2350a74f06

View File

@@ -110,7 +110,7 @@ void setup() { // BEGIN SETUP ------------------------------------
display.setTextSize(2); // Set text size on the display display.setTextSize(2); // Set text size on the display
display.setTextColor(WHITE); // Set text color on the display display.setTextColor(WHITE); // Set text color on the display
display.setCursor(36,18); // Set the display cursor to position display.setCursor(36,18); // Set the display cursor to position
display.println("NMA-1"); // Print on display display.println("NMM-1"); // Print on display
display.display(); // Refresh display display.display(); // Refresh display
delay(3000); delay(3000);
display.clearDisplay(); // Clean display display.clearDisplay(); // Clean display
@@ -125,21 +125,10 @@ ISR(TIMER1_COMPA_vect)
{ {
if (!rUP) // If button UP pressed if (!rUP) // If button UP pressed
{ {
if (menuState == 1) // and the menuState is 1 if (menuState == 1){} // Do nothing and leave menuState
{ // as it is (4)
menuState = 1; // then reset menuState to 1 else {
} menuState--;
else if (menuState == 2) // If menuState is 2
{
menuState = 1; // then reset menuState to 1
}
else if (menuState == 3) // If menuState is 3
{
menuState = 2; // then reset menuState to 2
}
else if (menuState == 4) // If menuState is 4
{
menuState = 3; // then reset menuState to 3
} }
while (!rUP); // Check if button is still pressed do nothing while (!rUP); // Check if button is still pressed do nothing
} }
@@ -147,21 +136,10 @@ ISR(TIMER1_COMPA_vect)
if (!rDOWN) // If button DOWN pressed if (!rDOWN) // If button DOWN pressed
{ {
if (menuState == 1) // and the menuState is 1 if (menuState == 4){} // Do nothing and leave menuState
{ // as it is (4)
menuState = 2; // then reset menuState to 2 else {
} menuState++;
else if (menuState == 2) // If menuState is 2
{
menuState = 3; // then reset menuState to 3
}
else if (menuState == 3) // If menuState is 3
{
menuState = 4; // then reset menuState to 4
}
else if (menuState == 4) // If menuState is 4
{
menuState = 4; // then reset menuState to 4
} }
while (!rDOWN); // Check if button is still pressed do nothing while (!rDOWN); // Check if button is still pressed do nothing
} }
@@ -171,48 +149,33 @@ ISR(TIMER1_COMPA_vect)
{ {
if (menuState == 1) // and the menuState is 1 if (menuState == 1) // and the menuState is 1
{ {
prevMenu = menuState; // and set prevMenu to 1
menuState = 10; // then reset menuState to 10 menuState = 10; // then reset menuState to 10
prevMenu = 1; // and set prevMenu to 1
} }
else if (menuState == 2) // If menuState is 2 else if (menuState == 2) // If menuState is 2
{ {
prevMenu = menuState; // and set prevMenu to 2
menuState = 11; // then reset menuState to 11 menuState = 11; // then reset menuState to 11
prevMenu = 2; // and set prevMenu to 2
} }
else if (menuState == 3) // If menuState is 3 else if (menuState == 3) // If menuState is 3
{ {
prevMenu = menuState; // and set prevMenu to 3
menuState = 12; // then reset menuState to 12 menuState = 12; // then reset menuState to 12
prevMenu = 3; // and set prevMenu to 3
} }
else if (menuState == 4) // If menuState is 4 else if (menuState == 4) // If menuState is 4
{ {
prevMenu = menuState; // and set prevMenu to 4
menuState = 13; // then reset menuState to 13 menuState = 13; // then reset menuState to 13
prevMenu = 4; // and set prevMenu to 4
} }
while (!rOK); // Check if button is still pressed do nothing while (!rOK); // Check if button is still pressed do nothing
} }
if (!rCANCEL) // If button OK pressed if (!rCANCEL) // If button OK pressed
{ {
if (prevMenu == 1) // and the prevMenu is 1 menuState = prevMenu;
{
menuState = 1; // then reset menuState to 1
}
else if (prevMenu == 2) // If prevMenu is 2
{
menuState = 2; // then reset menuState to 2
}
else if (prevMenu == 3) // If prevMenu is 3
{
menuState = 3; // then reset menuState to 3
}
else if (prevMenu == 4) // If prevMenu is 4
{
menuState = 4; // then reset menuState to 4
}
while (!rCANCEL); // Check if button is still pressed do nothing while (!rCANCEL); // Check if button is still pressed do nothing
} }
} }
// End of Timer compare interrupt --------------------------------------- // End of Timer compare interrupt ---------------------------------------
@@ -488,10 +451,3 @@ void write_dep (void)
mySerial.println(); // Print on display mySerial.println(); // Print on display
delay(100); delay(100);
} }