There is a lot of code there.
here are some pieces that illustrate generally what i have going on.....
Full code attached if needed.
void menuSelection(){
// depending on what menu is displayed do the proper function for the button press
if (menuNumber == 4 && millis() - lastButtonPress > debounce){
if (!screenButton4) {
menuNumber = 3;
buttonStates = false;
masterInputs = false;
slaveOutputs = false;
lastButtonPress = millis();
}
}
}
void getInputs(){
azimuthMaster = analogRead(azimuthPin); // read analog values from master arm
shoulderMaster = analogRead(shoulderPin);
elbowMaster = analogRead(elbowPin);
pitchMaster = analogRead(pitchPin);
wristMaster = analogRead(wristPin);
jawClose = analogRead(jawClosePin);
jawOpen = analogRead(jawOpenPin);
freeze = analogRead(freezePin);
Serial.println(elbowMaster);
screenButton1 = digitalRead(screenButton1Pin); // set variables to state of pins
screenButton2 = digitalRead(screenButton2Pin);
screenButton3 = digitalRead(screenButton3Pin);
screenButton4 = digitalRead(screenButton4Pin);
screenButton5 = digitalRead(screenButton5Pin);
screenButton6 = digitalRead(screenButton6Pin);
screenButton7 = digitalRead(screenButton7Pin);
screenButton8 = digitalRead(screenButton8Pin);
upButton = digitalRead(upButtonPin);
downButton = digitalRead(downButtonPin);
leftButton = digitalRead(leftButtonPin);
rightButton = digitalRead(rightButtonPin);
if (screenButton1 || screenButton2 || screenButton3 || screenButton4 || screenButton5 || screenButton6 || screenButton7 || screenButton8 || upButton || downButton || leftButton || rightButton){
anyButtonPressed = true; // if any face button is pressed make this true
}
else {
anyButtonPressed = false; // else no buttons are pressed
}
}
void Menu(){
switch (menuNumber){
case 4: // page to display diag sub pages (analog in, servo out, button state)
//left aligned position (leftSideOfScreen, vertical position, string )
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 20, "");
u8g.drawStr( 0, 55, "");
u8g.drawStr( 0, 90, "");
u8g.drawStr( 0, 125, "<- Diag");
//right aligned position (screenWidth-WidthOfString), vertical position, string)
u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 20, "");
u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 55, "");
u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 90, "");
u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 125, "");
break;
}
}
void Diag(){
if (masterInputs){ // display raw inputs from master controller
u8g.drawStr(screenWidth/2-(u8g.getStrWidth("Master Inputs"))/2, 12 ,"Master Inputs");
u8g.drawFrame((screenWidth/2-(u8g.getStrWidth("Master Inputs"))/2)-2, 0, u8g.getStrWidth("Master Inputs")+4, 14);
/* Display the name of the function aligned just left of center
then display the value 3 pixels right of the colon */
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Azimuth:"))+15),28,"Azimuth:"); // set label and align
u8g.setPrintPos(screenWidth/2+18,28); // set location of value print
u8g.print(azimuthMaster); // value to print
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Shoulder:"))+15),43,"Shoulder:");
u8g.setPrintPos(screenWidth/2+18,43);
u8g.print(shoulderMaster);
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Elbow:"))+15),58,"Elbow:");
u8g.setPrintPos(screenWidth/2+18,58);
u8g.print(elbowMaster);
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Pitch:"))+15),73,"Pitch:");
u8g.setPrintPos(screenWidth/2+18,73);
u8g.print(pitchMaster);
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Wrist:"))+15),88,"Wrist:");
u8g.setPrintPos(screenWidth/2+18,88);
u8g.print(wristMaster);
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Jaw Close:"))+15),103,"Jaw Close:");
u8g.setPrintPos(screenWidth/2+18,103);
u8g.print(jawClose);
u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Jaw Open:"))+15),118,"Jaw Open:");
u8g.setPrintPos(screenWidth/2+18,118);
u8g.print(jawOpen);
}
}
void draw(void) {
Menu();
Diag();
Logo();
}
void loop(void) {
getInputs();
menuSelection();
// picture loop
u8g.firstPage();
do {
draw();
}
// Serial.println("drawing");
while( u8g.nextPage() );
}
SC_Arm_Menu.ino (8.79 KB)
getInputs.ino (3.69 KB)
DisplayFunctions.ino (9.56 KB)