# rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos architecture

> Architecture diagram of the GitHub repository rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos
- Repository: https://github.com/rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos

## Overview

##### Main Components
- Hardware Interface:
- LEDs for Vehicles – Connected to Port B, bit 0.
- LEDs for Pedestrians – Connected to Port D, bits 2 and 3.
- Pedestrian Button – Connected to Port D, pin 6.
- Microcontroller:
- ATmega328P (as mentioned in the README for Wokwi and Arduino use).
- This is where the control logic (state machine) runs.
- Software/Firmware:
- Assembly Code Module (main.S): Represents low-level control logic.
- Arduino Sketch (sketch.ino): Provides an alternative implementation to run on an Arduino Uno.
- Development/Simulation Environment:

##### File Structure for Architectural Clues
- The top-level files (LICENSE, README.md) are standard, ensuring clarity.
- This dual implementation implies a layered design in the firmware that could be abstracted as a central control unit with hardware abstraction layers for interface.

a. Hardware Layer:
- External hardware components:
- Vehicle LED (Port B, bit 0)
- Pedestrian LEDs (Port D, bits 2 and 3)
- Pedestrian Button (Port D, pin 6)
b. Microcontroller/Control Unit:
- Center the ATmega328P as the core processing unit.
- State Machine Controller – manages the traffic light cycle based on the current state (five phases) and responds to the pedestrian button interrupt by switching to the priority phase.
- Interrupt/Signal Processor – handle the immediate transition upon button press.
c. Software/Firmware Modules:
- Assembly Module (main.S): Indicate that this module provides low-level control.
- Arduino Module (sketch.ino): Represents a higher-level, possibly more accessible implementation.
- Modules to show that they feed the same control logic into the microcontroller’s operation.
d. Simulation Environment:

##### Relationships/Interactions
- From the Pedestrian Button (input) to the Interrupt/Signal Processor in the Microcontroller.
- From the Microcontroller’s State Machine Controller to the LED outputs.
- This highlights the dependency on the external hardware signals and the response-by-control logic.

##### Architectural Patterns & Design Principles
- State machine pattern controlling the semáforo cycles.
- Separation of concerns:
- Hardware abstraction (interaction with ports and pins).
- Control logic (state transitions based on inputs).
- Simulation vs. deployment implementations (Assembly vs. Arduino code).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    VLED["Vehicle LED (Port B, Bit 0)"]:::hardware
    PLED["Pedestrian LED (Port D, Bits 2 & 3)"]:::hardware
    PBTN["Pedestrian Button (Port D, Pin 6)"]:::hardware

    %% Microcontroller and Control Sub-modules
    MCU["ATmega328P Controller"]:::controller
    SMC["State Machine Controller"]:::controller
    ISP["Interrupt/Signal Processor"]:::controller

    %% Software/Firmware Modules
    ASM["Assembly Code Module (main.S)"]:::firmware
    ARD["Arduino Sketch Module (sketch.ino)"]:::firmware

    %% Simulation Environment
    SIM["Wokwi Simulation"]:::simulation

    %% Relationships
    PBTN -->|"interrupt"| ISP
    MCU -->|"delegates"| SMC
    MCU -->|"handles"| ISP
    SMC -->|"control"| VLED
    SMC -->|"control"| PLED
    ASM -->|"lowlevel"| MCU
    ARD -->|"highlevel"| MCU
    SIM -->|"simulates"| MCU

    %% Styles
    classDef hardware fill:#FFCCCB,stroke:#333,stroke-width:2px;
    classDef controller fill:#C3FDB8,stroke:#333,stroke-width:2px;
    classDef firmware fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef simulation fill:#D5F5E3,stroke:#333,stroke-width:2px;

    %% Click Events
    click SIM "https://github.com/rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos/blob/main/wokwik/diagram.json"
    click MCU "https://github.com/rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos/blob/main/wokwik/main.S"
    click ASM "https://github.com/rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos/blob/main/wokwik/main.S"
    click ARD "https://github.com/rubengameztorrijos/semaforo_pulsador_peatonal_y_vehiculos/blob/main/wokwik/sketch.ino"
```
