Elevator project for highschool PLTW

My team is trying program an elevator to go to three different floors using three different bump switches. We attempted use a series of if-else statements, 3 of them in fact, 1 for each floor. We also tried to use a series of 6 if statements that have gotten the best results but not what we intended. We created 2 if scenarios for each floor you would be starting at. For example, there was an if statement for floor 1 that would take it to floor 2, and an if statement to take it to floor 3. What happened was, only 1 of each would work for each floor, and it wasn’t always necessarily the first if statement either, it’s just always one or the other for each floor. It seems our 6 if statement program would work if we could find a way for the program to realize that if one of the two statements for each floor is not to be used, then to go to the next scenario for that floor if it is activated. If anyone could give us any suggestions at all they would be greatly appreciated. :slight_smile:

Wow, thats confusing. So the idea is that you push a bumper switch and the elevator goes to that floor? or does the switch get tripped by the elevator itself?

I guess you need to track the current position of the elevator in a variable and then decide where it needs to go based on switch input.

Often I will combine several inputs and then use a switch statement, but this a just a personal style I use and not the only way to do this.

for example (pseudocode, assuming a switch can have values 0 or 1)

MySwitches = (switch1 * 4) + (switch2 * 2) + switch3

there are 8 possible values, 0 through 7, then use

    case 0: // nothing pushed
    case 1: // first switch pushed
        // now call an elevator move function
        // it needs to decide are we already in position or do we
        // need to go up or down.
    case 2: // second switch pushed
        // more elevator moving
    case 3: // switch 1 and switch 2 are pushed
        // where are we now, which switch has priority
    // etc...