Skip to content

Instantly share code, notes, and snippets.

@arslnb
Created November 14, 2012 12:44
Show Gist options
  • Save arslnb/4071898 to your computer and use it in GitHub Desktop.
Save arslnb/4071898 to your computer and use it in GitHub Desktop.
Minimum pin consuming LCD display
void commandProcessor(void) {
int lastCounts;
int counts;
boolean firstCount = true;
if (Encoder.buttonDown()) { // Read push button status (Ground true => 0=down)
while (Encoder.buttonDown()); // Do nothing while button is depressed
// Display menu
LCD.printString(MSG_FCT_SELECT, 1);
counts = 0;
Encoder.setCounter(counts, 0, 3);
firstCount = true;
while (!Encoder.buttonDown()) { // While button is not depressed
lastCounts = counts;
counts = Encoder.getCounter(); // Get counter value
if ((lastCounts != counts) || firstCount) { // If counter has changed since last display
firstCount = false;
LCD.printString(FunctionIndexToString(counts), 2);
}
}
while (Encoder.buttonDown()); // Wait button release
switch(counts) {
// Run control
case 0:
LCD.printString(MSG_FCT_RUN_CONTROL, 1);
counts = 0;
Encoder.setCounter(counts, 0, 1);
firstCount = true;
while (!Encoder.buttonDown()) { // While button is not depressed
lastCounts = counts;
counts = Encoder.getCounter(); // Get counter value
if ((lastCounts != counts) || firstCount) { // If counter has changed since last display
firstCount = false;
LCD.printString(RunControlIndexToString(counts), 2);
}
}
while (Encoder.buttonDown()) // Do nothing while button is depressed
run_state = counts;
break;
// Function: cycle duration
case 1:
LCD.printString(MSG_FCT_DURATION, 1);
counts = tim_cycleDuration;
Encoder.setCounter(counts, 100, 10000);
firstCount = true;
while (!Encoder.buttonDown()) { // While button is not depressed
lastCounts = counts;
counts = Encoder.getCounter(); // Get counter value
if ((lastCounts != counts) || firstCount) { // If counter has changed since last display
firstCount = false;
counts = lastCounts + pow((counts - lastCounts), 3); // Non linear counter (counts booster): Powering to 3 prevents from caring about the sign
Encoder.setCounter(counts); // Update counter
// Display frequency
LCD.eraseBuffer();
LCD.insertInteger(counts, 5);
LCD.insertString("ms", 7, true);
LCD.printBuffer(2);
}
delay(50);
}
while (Encoder.buttonDown()); // Wait for button release
tim_cycleDuration = counts;
computeDurations();
break;
// Function: on/off ratio
case 2:
LCD.printString(MSG_FCT_ON__OFF_RATIO, 1);
counts = tim_onOffRatio;
Encoder.setCounter(counts, 1, 99);
firstCount = true;
while (!Encoder.buttonDown()) { // While button is not depressed
lastCounts = counts;
counts = Encoder.getCounter(); // Get counter value
if ((lastCounts != counts) || firstCount) { // If counter has changed since last display
firstCount = false;
Encoder.setCounter(counts); // Update counter
// Display frequency
LCD.eraseBuffer();
LCD.insertInteger(counts, 5);
LCD.insertString("%", 7, true);
LCD.printBuffer(2);
}
}
while (Encoder.buttonDown()); // Wait for button release
tim_onOffRatio = counts;
computeDurations();
break;
// Exit
case 3:
break;
}
LCD.printString(MSG_FIRMWARE, 1);
LCD.printString(" ", 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment