Introduction video coming soon

Elevator Simulation

Level: 7/10
Elevator Simulation
Quick Start
  1. Download and install UDUSimp and sign in with your account.
  2. Choose a workspace folder; the libraries and start code are downloaded into its c_… / py_… folders.
  3. Start the simulation, then write and run your code in the workspace.

Function List

Purpose of the Simulation

Introductory programming education in languages such as C, C++, and Python is generally taught through console applications. As a result, the output of developed code is displayed only on the console. This prevents students from visualizing the program flow and fully understanding its behavior.

The purpose of this simulation is to provide an environment where students can see how their code actually works. To increase realism, sensors, motors, and indicator panels can each be controlled independently, and the output value of each sensor can be read.

After downloading and installing the UDUSimp program, you can run any simulation and start developing code using your preferred editor. Recommended editor: Visual Studio Code.

The difficulty level of the elevator simulation is rated 7 out of 10.

General

1 – Features
- Movable Cabin
- Movable Floor Doors *
- Cabin Limit Sensor Indicators *
- Cabin Door Limit Sensors *
- Illuminated Floor Buttons Inside Cabin
- Cabin Direction Indicator Light *
- Elevator Call Buttons *

2 – Task and Definition
Examine the elevators used in daily life and their operating logic. Develop the code required for the elevator to operate in a 3-floor building.
Example: When the elevator is on the 3rd floor and is called from the 1st floor, it must:
1- Close the cabin door
2- Move the cabin downward
3- Detect that it has reached the 1st floor through the floor sensor data and stop

Note: While performing these operations, do not forget to activate and deactivate the Elevator Indicator Lights. This way, you will inform those waiting for the elevator.

General

Connect to Simulation

sim_connect()

Establishes connection between the simulation and your code.

#include "elevator.h"
int main() {
    sim_connect();
    return 0;
}
from elevator import *

sim_connect()

Disconnect from Simulation

sim_disconnect()

Terminates the connection between the simulation and your code.

#include "elevator.h"
int main() {
    sim_connect();
    sim_disconnect();
    return 0;
}
from elevator import *

sim_connect()
sim_disconnect()

Door Control

door(int floor, int openClose)

Runs the door motor on the specified floor.
1st param: floor number (1-3)
2nd param: DOOR_OPEN (1) = Open, DOOR_CLOSE (2) = Close, DOOR_STOP (0) = Stop

Stop the motor when the door is fully open (door_open_read = 1) or fully closed (door_sensor_read = 0); otherwise the error flag (get_error) becomes 1.

Example:
door(1, DOOR_CLOSE) → 1st floor door closes
door(3, DOOR_OPEN) → 3rd floor door opens

#include "elevator.h"
int main() {
    sim_connect();
    door(1, DOOR_CLOSE); // 1. kat kapat
    door(3, DOOR_OPEN);  // 3. kat ac
    return 0;
}
from elevator import *

sim_connect()
door(1, DOOR_CLOSE)  # 1. kat kapat
door(3, DOOR_OPEN)   # 3. kat ac

Floor Button Light

floor_button_light(int floor, int direction, int onOff)

Controls the backlight of the call button on the specified floor.
1st param: floor number
2nd param: direction — 1 = Up (DIR_UP), 0 = Down (DIR_DOWN)
3rd param: 1 = On, 0 = Off

Example:
floor_button_light(2, DIR_DOWN, 1) → 2nd floor down button light turns on

#include "elevator.h"
int main() {
    sim_connect();
    floor_button_light(2, DIR_DOWN, 1); // 2.kat asagi isik ac
    floor_button_light(2, DIR_DOWN, 0); // 2.kat asagi isik kapat
    return 0;
}
from elevator import *

sim_connect()
floor_button_light(2, DIR_DOWN, 1)  # 2.kat asagi isik ac
floor_button_light(2, DIR_DOWN, 0)  # 2.kat asagi isik kapat

Cabin Button Light

cabin_button_light(int button, int onOff)

Controls the backlight of a button inside the cabin.
1st param: button number (floor)
2nd param: 1 = On, 0 = Off

Example:
cabin_button_light(1, 0) → cabin floor 1 button light turns off

#include "elevator.h"
int main() {
    sim_connect();
    cabin_button_light(1, 0); // 1.kat dugme sondur
    cabin_button_light(2, 1); // 2.kat dugme yak
    return 0;
}
from elevator import *

sim_connect()
cabin_button_light(1, 0)  # 1.kat dugme sondur
cabin_button_light(2, 1)  # 2.kat dugme yak

Cabin Display

cabin_display(int floor)

Prints the floor number on the LCD screen inside the cabin.
1st param: floor number to display

Example:
cabin_display(2) → displays 2 on screen

#include "elevator.h"
int main() {
    sim_connect();
    cabin_display(2);
    return 0;
}
from elevator import *

sim_connect()
cabin_display(2)

Cabin Motor

cabin_motor(int direction)

Runs the cabin motor.
1st param: CABIN_UP (1) = Up, CABIN_DOWN (2) = Down, CABIN_STOP (0) = Stop

If the cabin moves past the top (3rd) or bottom (1st) floor, the error flag (get_error) becomes 1.

Example:
cabin_motor(CABIN_UP) → cabin moves up
cabin_motor(CABIN_DOWN) → cabin moves down
cabin_motor(CABIN_STOP) → cabin stops

#include "elevator.h"
int main() {
    sim_connect();
    cabin_motor(CABIN_UP);   // yukari
    cabin_motor(CABIN_DOWN); // asagi
    cabin_motor(CABIN_STOP); // dur
    return 0;
}
from elevator import *

sim_connect()
cabin_motor(CABIN_UP)    # yukari
cabin_motor(CABIN_DOWN)  # asagi
cabin_motor(CABIN_STOP)  # dur

Get Error

int err = get_error()

Returns whether an error has occurred in the simulation.
Returns 1 → a limit was exceeded (the cabin passed the top/bottom floor or a door passed its fully open/closed position)
Returns 0 → no error
The error flag clears itself.

#include "elevator.h"
int main() {
    sim_connect();
    int err = get_error();
    if(err == 1)
        printf("Hata olustu!");
    return 0;
}
from elevator import *

sim_connect()
err = get_error()
if err == 1:
    print("Hata olustu!")

Read Floor Button

int l = floor_button_read(int floor, int direction)

Reads whether the directional call button on the specified floor is pressed.
1st param: floor number
2nd param: direction — 1 = Up (DIR_UP), 0 = Down (DIR_DOWN)
Returns 1 → pressed, 0 → not pressed

Example:
floor_button_read(1, DIR_DOWN) → is 1st floor down button pressed?

#include "elevator.h"
int main() {
    sim_connect();
    int l = floor_button_read(1, DIR_DOWN);
    if(l == 1)
        printf("1.kat asagi dugmesine basildi");
    return 0;
}
from elevator import *

sim_connect()
l = floor_button_read(1, DIR_DOWN)
if l == 1:
    print("1.kat asagi dugmesine basildi")

Read Cabin Button

int cb = cabin_button_read(int button)

Reads whether the specified button inside the cabin is pressed.
1st param: button number (floor)
Returns 1 → pressed, 0 → not pressed

Example:
cabin_button_read(2) → is cabin floor 2 button pressed?

#include "elevator.h"
int main() {
    sim_connect();
    int cb = cabin_button_read(2);
    if(cb == 1)
        printf("Kabin 2.kat dugmesine basildi");
    return 0;
}
from elevator import *

sim_connect()
cb = cabin_button_read(2)
if cb == 1:
    print("Kabin 2.kat dugmesine basildi")

Read Door Sensor

int ds = door_sensor_read(int floor)

Reads whether the door on the specified floor is fully closed.
Returns 1 → door is not fully closed (opening / open)
Returns 0 → door is fully closed

Example:
door_sensor_read(2) → is the 2nd floor door open?

#include "elevator.h"
int main() {
    sim_connect();
    int ds = door_sensor_read(2);
    if(ds == 1)
        printf("2.kat kapisi acik");
    return 0;
}
from elevator import *

sim_connect()
ds = door_sensor_read(2)
if ds == 1:
    print("2.kat kapisi acik")

Read Door Fully Open Sensor

int op = door_open_read(int floor)

Reads whether the door on the specified floor is fully open.
Returns 1 → door fully open, 0 → not fully open
While opening, stop the motor when this becomes 1.

Example:
door_open_read(2) → is the 2nd floor door fully open?

#include "elevator.h"
int main() {
    sim_connect();
    door(2, DOOR_OPEN);
    while(door_open_read(2) == 0)
        Sleep(10);           // tam acilana kadar bekle
    door(2, DOOR_STOP);
    return 0;
}
from elevator import *
import time

sim_connect()
door(2, DOOR_OPEN)
while door_open_read(2) == 0:
    time.sleep(0.01)      # tam acilana kadar bekle
door(2, DOOR_STOP)

Read Cabin Motion

int cm = cabin_motion_read()

Reads the current state of the cabin motor.
Returns:
0 → cabin stopped (CABIN_STOP)
1 → moving up (CABIN_UP)
2 → moving down (CABIN_DOWN)

#include "elevator.h"
int main() {
    sim_connect();
    int cm = cabin_motion_read();
    if(cm != CABIN_STOP)
        printf("Kabin hareket ediyor");
    return 0;
}
from elevator import *

sim_connect()
cm = cabin_motion_read()
if cm != CABIN_STOP:
    print("Kabin hareket ediyor")

Read Door Motion

int dm = door_motion_read(int floor)

Reads the current state of the door motor on the specified floor.
Returns:
0 → door motor stopped (DOOR_STOP)
1 → door opening (DOOR_OPEN)
2 → door closing (DOOR_CLOSE)

Example:
door_motion_read(1) → is the 1st floor door moving?

#include "elevator.h"
int main() {
    sim_connect();
    int dm = door_motion_read(1);
    if(dm != DOOR_STOP)
        printf("1.kat kapisi hareket ediyor");
    return 0;
}
from elevator import *

sim_connect()
dm = door_motion_read(1)
if dm != DOOR_STOP:
    print("1.kat kapisi hareket ediyor")

Read Cabin Position Sensor

int cs = cabin_sensor_read(int floor)

Reads whether the cabin is positioned at the specified floor.
Returns 1 → cabin is at that floor, 0 → not

Example:
cabin_sensor_read(3) → is cabin at 3rd floor?

#include "elevator.h"
int main() {
    sim_connect();
    int cs = cabin_sensor_read(3);
    if(cs == 1)
        printf("Kabin 3.katta");
    return 0;
}
from elevator import *

sim_connect()
cs = cabin_sensor_read(3)
if cs == 1:
    print("Kabin 3.katta")