Intermittent 4180 project

Dependencies:   4DGL-uLCD-SE Motordriver PinDetect RemoteIR mbed-rtos mbed

Fork of Menu4180 by Brandon Lasater

main.cpp

Committer:
blasater3
Date:
2015-05-01
Revision:
0:a693014b42b1
Child:
1:6a969b21c9de

File content as of revision 0:a693014b42b1:

#include "mbed.h"
#include "uLCD_4DGL.h"


uLCD_4DGL lcd(p28, p27, p29);
DigitalIn pb(p7);
DigitalIn pb1(p10);
DigitalIn pb2(p13);
DigitalIn pb3(p16);

int main() {
    lcd.baudrate(3000000);
    lcd.background_color(0);
    lcd.cls();
    
    pb.mode(PullUp); //Intitial Pusbutton Setup
    pb1.mode(PullUp);
    pb2.mode(PullUp);
    pb3.mode(PullUp);
    wait(.001);
    
    lcd.locate(1,2); //Initial Menu Setup
    lcd.printf("Add Stop<");
    lcd.locate(1,4);
    lcd.printf("Remove Stop ");
    lcd.locate(1,6);
    lcd.printf("Exit ");
    
    bool count = false;
    int old_pb=1;
    int new_pb;
    
    int count1=0;
    int old_pb1=1;
    int new_pb1;
    
    int old_pb2=1;
    int new_pb2;
    
    bool count3 = false; //whether enter has been pressed
    bool count4 = true; //whether it is currently on add stops or remove stops
    int old_pb3=1;
    int new_pb3;
    bool Menu = true;
 //Set up the booleans determining what stops are currently being serviced
    bool stop1 = true;
    bool stop2 = true;
    bool stop3 = true;
    bool stop4 = true;
    bool running = true;
    int stop = 1;
    
    while(1) {
        new_pb = pb;
        new_pb1 = pb1;
        new_pb2 = pb2;
        new_pb3 = pb3;
        
        if(!Menu) {
            if(running && stop == 1){
                lcd.locate(1,5);
                lcd.printf("Moving to Stop1 ");    
            }
            if(!running && stop == 1){
                lcd.locate(1,5);
                lcd.printf("Waiting at Stop1");    
            }
            if(running && stop == 2){
                lcd.locate(1,5);
                lcd.printf("Moving to Stop2 ");    
            }
            if(!running && stop == 2){
                lcd.locate(1,5);
                lcd.printf("Waiting at Stop2");    
            }
            if(running && stop == 3{
                lcd.locate(1,5);
                lcd.printf("Moving to Stop3");    
            }
            if(!running && stop == 3{
                lcd.locate(1,5);
                lcd.printf("Waiting at Stop3);    
            }
            if(running && stop == 4{
                lcd.locate(1,5);
                lcd.printf("Moving to Stop4 ");    
            }
            if(!running && stop == 4){
                lcd.locate(1,5);
                lcd.printf("Waiting at Stop4");    
            }
        }    
        
        if(Menu) { //All of the below runs the menu interactions
        if ((new_pb==0) && (old_pb==1)) count = !count;
        if ((new_pb1==0) && (old_pb1==1) && count1 < 3) count1++;
        if ((new_pb2==0) && (old_pb2==1) && count1 > 0) count1--;
        if ((new_pb3==0) && (old_pb3==1)) {
            count3 = !count3;
            lcd.cls();
            count1 = 0;
        }
        
        if(count && !count3){
            lcd.cls();
            count1 = 0;
            count = false;
        }
        
        if(count && count3 && count4){
            if(count1 == 0) stop1 = true;
            if(count1 == 1) stop2 = true;
            if(count1 == 2) stop3 = true;
            if(count3 == 3) stop4 = true;
            count = false;
        }
        
        if(count && count3 && count4){
            if(count1 == 0) stop1 = false;
            if(count1 == 1) stop2 = false;
            if(count1 == 2) stop3 = false;
            if(count3 == 3) stop4 = false;
            count = false;
        }
        
        if(!count) {
        if(!count3) {
            lcd.locate(1,1);
            lcd.printf("             ");
        }

        if(count3 && count4 && count1==0) {
            lcd.locate(1,1);
            lcd.printf("Add stops");
            lcd.locate(1,2); //Initial Menu Setup for adding stops
            lcd.printf("Stop 1<        ");
            lcd.locate(1,4);
            lcd.printf("Stop 2         ");
            lcd.locate(1,6);
            lcd.printf("Stop 3 ");
            lcd.locate(1,8);
            lcd.printf("Stop 4 ");
        }
        if(count3 && count4 && count1==1) {
            lcd.locate(1,1);
            lcd.printf("Add stops");
            lcd.locate(1,2); //Initial Menu Setup for adding stops
            lcd.printf("Stop 1         ");
            lcd.locate(1,4);
            lcd.printf("Stop 2<        ");
            lcd.locate(1,6);
            lcd.printf("Stop 3 ");
            lcd.locate(1,8);
            lcd.printf("Stop 4 ");
        }
        if(count3 && count4 && count1==2) {
            lcd.locate(1,1);
            lcd.printf("Add stops");
            lcd.locate(1,2); //Initial Menu Setup for adding stops
            lcd.printf("Stop 1         ");
            lcd.locate(1,4);
            lcd.printf("Stop 2         ");
            lcd.locate(1,6);
            lcd.printf("Stop 3<");
            lcd.locate(1,8);
            lcd.printf("Stop 4 ");
        }
        if(count3 && count4 && count1==3) {
            lcd.locate(1,1);
            lcd.printf("Add stops");
            lcd.locate(1,2); //Initial Menu Setup for adding stops
            lcd.printf("Stop 1         ");
            lcd.locate(1,4);
            lcd.printf("Stop 2         ");
            lcd.locate(1,6);
            lcd.printf("Stop 3 ");
            lcd.locate(1,8);
            lcd.printf("Stop 4<");
        }
        
        if(count3 && !count4 && count1 == 0) {
            lcd.locate(1,1);
            lcd.printf("Remove Stops");
            lcd.locate(1,2); //Initial Menu Setup for removing
            lcd.printf("Stop 1<        ");
            lcd.locate(1,4);
            lcd.printf("Stop 2         ");
            lcd.locate(1,6);
            lcd.printf("Stop 3 ");
            lcd.locate(1,8);
            lcd.printf("Stop 4 ");
        }
        if(count3 && !count4 && count1 == 1) {
            lcd.locate(1,1);
            lcd.printf("Remove Stops");
            lcd.locate(1,2); //Initial Menu Setup for removing
            lcd.printf("Stop 1         ");
            lcd.locate(1,4);
            lcd.printf("Stop 2<        ");
            lcd.locate(1,6);
            lcd.printf("Stop 3 ");
            lcd.locate(1,8);
            lcd.printf("Stop 4 ");
        }
        if(count3 && !count4 && count1 == 2) {
            lcd.locate(1,1);
            lcd.printf("Remove Stops");
            lcd.locate(1,2); //Initial Menu Setup for removing
            lcd.printf("Stop 1         ");
            lcd.locate(1,4);
            lcd.printf("Stop 2         ");
            lcd.locate(1,6);
            lcd.printf("Stop 3<");
            lcd.locate(1,8);
            lcd.printf("Stop 4 ");
        }if(count3 && !count4 && count1 == 3) {
            lcd.locate(1,1);
            lcd.printf("Remove Stops");
            lcd.locate(1,2); //Initial Menu Setup for removing
            lcd.printf("Stop 1         ");
            lcd.locate(1,4);
            lcd.printf("Stop 2         ");
            lcd.locate(1,6);
            lcd.printf("Stop 3 ");
            lcd.locate(1,8);
            lcd.printf("Stop 4<");
        }
        if(count1 == 0 && !count3) {
            lcd.locate(1,2); //Initial Menu Setup
            lcd.printf("Add Stop<"); 
            count4 = true;   
        } if(count1 != 0 && !count3) {
            lcd.locate(1,2); //Initial Menu Setup
            lcd.printf("Add Stop ");
        }
        
        if(count1 == 1 && !count3) {
            lcd.locate(1,4);
            lcd.printf("Remove Stop<");   
            count4 = false; 
        } if(count1 != 1 && !count3) {
            lcd.locate(1,4);
            lcd.printf("Remove Stop ");
        }
        
        if(count1 == 2 && !count3) {
            lcd.locate(1,6);
            lcd.printf("Exit<");    
        } if(count1 != 2 && !count3) {
            lcd.locate(1,6);
            lcd.printf("Exit ");
        }
        }
        }
        
        
        old_pb = new_pb;
        old_pb1 = new_pb1;
        old_pb2 = new_pb2;
        old_pb3 = new_pb3;
    }
}