Writing code for my elevator simulator project

I am currently writing an elevator simulator code for a project that I am making, I ended up getting a bit of help for how to set the code up. The issue is, I don't know what I am doing. Any help will be appreciated

Here is the code that I am writing

int CurrentPos = 1; // Starting Position of the elevator
int Calls[] = {0,0,0,0}; // Call Button Data Storage **DO NOT MESS WITH!!**
int NextFloor = 1;
int Directions = 0; //0 = down, 1 = n 2 = up
int TRAVEL_TIME = 2000;
const int Buttons[] = {2,3,4,5}; //Button Pin Reference
const int PressedLED[] = {6,7,8,9}; // Button LED Reference
const int MovingLED[] = {10,11,12,13};

void setup() {
 //Button Input Setup
for (int i = 0; i = 3; i++){
 pinMode (Buttons[i], INPUT_PULLUP);
}
//Pressed LED Setup
for (int i = 0; i = 3; i++){
 pinMode(PressedLED[i], OUTPUT);
}
//Moving LED Setup
for (i = 0l i = 3; i++){
 pinMode(MovingLED[i], OUTPUT);
}
}

void loop() {
//Are there any calls?
 //Ifbutton 1,2,3,4
   //Calls[button -1] =1
   //Button LED

   //What floor to next
     //Cur = next
       //Get next floor based on Calls

//If traveling for the first time
 //counter = 0;
//else not 
 //counter++

//If counter = TAVEL TIME
 //counter =0
 //curent possition to +/- 1 floor based on direction

}

Then the solution is a flow chart or logic diagram showing what you want to do and the decisions necessary to make it all work.

In setup(), you can perform all those config actions within a single for() structure.

Otherwise, remember that = is the assignment operator, == is for comparison.

Elevators are a popular project that we see here often. A search of this site should show what others have done.

We don't either, although we could guess you have a single elevator car serving four floors.

Regular elevators have buttons for going up and down.

So maybe say a bit about how you want your elevator to work, or appear to be working.

a7

After some tweaking, I managed to get it working, but there are a few things I want to add

Cool.

It could not hurt to post the best current version you have so we could play elevator.

a7

First of all you should add the "chrystal ball"-module to your µC that can beam pictures of your imagination into the forum-members head to understand what you want to add.

Oh you don't know where to buy the "chrystal ball"-module ??
Me not either! :wink:
So maybe describing in detail what functionality you want to add is a good solution.

best regards Stefan

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.