Introduction video coming soon

Garage Simulation

Level: 6/10
Garage 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

FunctionDescription
sim_connect() Connect to Simulation
sim_disconnect() Disconnect from Simulation
door_motor(int direction) Garage Door Motor
garage_lamp(int onOff) Garage Lamp
warning_light(int r, int g, int b, int onOff) Warning Light (RGB)
warning_light_on() Warning Light On (No Color Change)
warning_light_off() Warning Light Off
int k = key_read(int key) Read Keypad
int p = door_pos_read() Read Door Position Sensor
int dm = door_motor_read() Read Door Motor State
int gl = garage_lamp_read() Read Garage Lamp State
int wl = warning_light_read() Read Warning Light State

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, door motor, lamps, RGB warning light, keypad, and door position sensor can each be controlled independently, and the state of every component 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 garage simulation is rated 6 out of 10.

General

1 – Features
- Up / Down / Stop controlled garage door motor
- Switchable garage interior lamp
- RGB color-changing warning light *
- Numeric keypad with 0-9, # and X keys *
- Door position sensor (0-100% closed) *
- State-read functions for all components *

2 – Task and Definition
Examine smart garage systems used in daily life and their operating logic. Develop the code required to open the door based on a keypad password, automatically stop the motor using sensor data, and signal the state via the RGB warning light.
Example scenarios:
1- Move the door upward when the correct password is entered on the keypad
2- Automatically stop the motor and turn the warning light green when the door is fully open (position 0)
3- Turn the warning light red on a wrong password attempt and reset it with the X key
must be implemented.

Note: A movement started with door_motor() will run until the door hits the limit switch unless stopped when door_pos_read() reaches the target position. Re-read the position every loop and stop the motor at the correct moment.

Connect to Simulation

sim_connect()

Establishes connection between the simulation and your code.

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

sim_connect()

Disconnect from Simulation

sim_disconnect()

Terminates the connection between the simulation and your code.

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

sim_connect()
sim_disconnect()

Garage Door Motor

door_motor(int direction)

Runs the garage door motor.
1st param:
DOOR_UP (1) = Up (door opens)
DOOR_DOWN (2) = Down (door closes)
DOOR_STOP (0) = Stop

Example:
door_motor(DOOR_UP) → door starts opening
door_motor(DOOR_DOWN) → door starts closing
door_motor(DOOR_STOP) → motor stops

#include "garage.h"
int main() {
    sim_connect();
    door_motor(DOOR_UP);    // ac
    door_motor(DOOR_DOWN);  // kapat
    door_motor(DOOR_STOP);  // dur
    return 0;
}
from garage import *

sim_connect()
door_motor(DOOR_UP)     # ac
door_motor(DOOR_DOWN)   # kapat
door_motor(DOOR_STOP)   # dur

Garage Lamp

garage_lamp(int onOff)

Turns the garage interior lamp on or off.
1st param: LAMP_ON (1) = On, LAMP_OFF (0) = Off

Example:
garage_lamp(LAMP_ON) → lamp turns on
garage_lamp(LAMP_OFF) → lamp turns off

#include "garage.h"
int main() {
    sim_connect();
    garage_lamp(LAMP_ON);  // yak
    garage_lamp(LAMP_OFF); // sondur
    return 0;
}
from garage import *

sim_connect()
garage_lamp(LAMP_ON)   # yak
garage_lamp(LAMP_OFF)  # sondur

Warning Light (RGB)

warning_light(int r, int g, int b, int onOff)

Turns the warning light on or off with the desired color.
Parameters:
r,g,b → RGB color values 0-255
onOff → WARN_ON (1) = On, WARN_OFF (0) = Off

Example:
warning_light(255,0,0, WARN_ON) → red on
warning_light(0,255,0, WARN_ON) → green on
warning_light(0,0,0, WARN_OFF) → off

#include "garage.h"
int main() {
    sim_connect();
    warning_light(255, 0, 0, WARN_ON); // kirmizi
    warning_light(0, 255, 0, WARN_ON); // yesil
    warning_light(0, 0, 0, WARN_OFF);  // sondur
    return 0;
}
from garage import *

sim_connect()
warning_light(255, 0, 0, WARN_ON)  # kirmizi
warning_light(0, 255, 0, WARN_ON)  # yesil
warning_light(0, 0, 0, WARN_OFF)   # sondur

Warning Light On (No Color Change)

warning_light_on()

Turns the warning light on with its current color. Does not change RGB values.
Uses the last color set by warning_light().

#include "garage.h"
int main() {
    sim_connect();
    warning_light(0, 0, 255, WARN_ON); // once mavi ayarla
    warning_light_off();
    warning_light_on();                // tekrar mavi yan
    return 0;
}
from garage import *

sim_connect()
warning_light(0, 0, 255, WARN_ON)  # once mavi ayarla
warning_light_off()
warning_light_on()                 # tekrar mavi yan

Warning Light Off

warning_light_off()

Turns the warning light off. Does not clear color settings; calling warning_light_on() again will light it with the same color.

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

sim_connect()
warning_light_off()

Read Keypad

int k = key_read(int key)

Reads whether the specified key on the keypad is pressed.
1st param:
0-9 → digit keys
10 → # key
11 → X (cancel) key
Returns 1 → key is pressed, 0 → not pressed

Example:
key_read(5) → is key 5 pressed?
key_read(10) → is # key pressed?
key_read(11) → is X key pressed?

#include "garage.h"
int main() {
    sim_connect();
    int k = key_read(5);
    if(k == 1)
        printf("5 tusuna basildi");
    return 0;
}
from garage import *

sim_connect()
k = key_read(5)
if k == 1:
    print("5 tusuna basildi")

Read Door Position Sensor

int p = door_pos_read()

Reads the garage door's closed percentage.
Returned value 0-100:
0 → door fully open
100 → door fully closed
50 → door half closed

Example:
int p = door_pos_read() → p = 100 (door fully closed)

#include "garage.h"
int main() {
    sim_connect();
    int p = door_pos_read();
    if(p >= 100)
        door_motor(DOOR_STOP);  // tam kapali, motoru durdur
    return 0;
}
from garage import *

sim_connect()
p = door_pos_read()
if p >= 100:
    door_motor(DOOR_STOP)   # tam kapali, motoru durdur

Read Door Motor State

int dm = door_motor_read()

Reads the current state of the garage door motor.
Returns:
0 → motor stopped
1 → door moving up
2 → door moving down

#include "garage.h"
int main() {
    sim_connect();
    int dm = door_motor_read();
    if(dm == 0)
        printf("Kapi durdu");
    return 0;
}
from garage import *

sim_connect()
dm = door_motor_read()
if dm == 0:
    print("Kapi durdu")

Read Garage Lamp State

int gl = garage_lamp_read()

Reads the current state of the garage interior lamp.
Returns 1 → lamp is on
Returns 0 → lamp is off

#include "garage.h"
int main() {
    sim_connect();
    int gl = garage_lamp_read();
    if(gl == 1)
        printf("Garaj lambasi acik");
    return 0;
}
from garage import *

sim_connect()
gl = garage_lamp_read()
if gl == 1:
    print("Garaj lambasi acik")

Read Warning Light State

int wl = warning_light_read()

Reads the current state of the warning light.
Returns 1 → light is on
Returns 0 → light is off

#include "garage.h"
int main() {
    sim_connect();
    int wl = warning_light_read();
    if(wl == 1)
        printf("Uyari lambasi acik");
    return 0;
}
from garage import *

sim_connect()
wl = warning_light_read()
if wl == 1:
    print("Uyari lambasi acik")