Skip to content
AndreaRandazzoPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

IR Sensor Simulator

A Java simulation of an infrared beam sensor system using the Observer pattern. The sensor detects whether an object is blocking an infrared beam and notifies all registered observers, each reacting independently.

Architecture

Class/Interface Role
IrSensor The observed. Runs on a separate thread, polls beam state every second via AtomicBoolean, notifies observers on state change
SensorObserver Interface with a single method onStateChanged(State state)
Gate Observer. Starts a 5-second countdown to close when beam is clear. Cancels it if beam is blocked again
AlarmSystem Observer. Alerts security 5 seconds after detecting an intruder. Cancels if beam clears
SimulatedEnvironment Reads keyboard input to simulate objects passing through the beam
Main Wires all components together and starts the sensor thread

Prerequisites

  • Java 17+
  • No external dependencies

Run

Launch Main.java from your IDE or via terminal:

javac -d out src/com/main/*.java
java -cp out com.main.Main

Commands

Key Action
b Block the beam (object detected)
c Clear the beam (no object)
q Quit

Extending

To add a new observer, create a class that implements SensorObserver and register it in Main with irSensor.addObserver(yourObserver).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages