This module demonstrates how to implement a vehicle lighting control system using analog input acquisition and FlexIO-based LED driving on NXP S32K3 microcontrollers.
The application reads analog inputs from the Analog Key Click module (six push-buttons, each generating a distinct voltage level) and converts them into commands that drive a 4x4 RGB LED matrix. Each button press activates a specific lighting function — low beam, high beam, turn signals, brake lights, or hazard lights — while safety interlocks and blinking patterns run continuously in the background, mimicking how a real automotive Body Control Module (BCM) manages vehicle lighting.
This example is based on Application Code Hub demonstrations for:
In this workshop, the Analog Key Click simulates six vehicle lighting controls. When the student presses a button, an analog voltage proportional to the pressed key is read by the MCU through the ADC (with software debouncing), decoded into a specific lighting command, and translated into an RGB pattern generated by the FlexIO peripheral. The 4x4 RGB Click then displays the corresponding automotive lighting behavior in real time — warm white for low beams, cool white for high beams, blinking amber for turn signals and hazards, and red for brake lights.
The three elements capture exactly the basic idea of the system in the demo:
This matches the classic flow of an embedded body-control system: sensor → processing → actuator.
The system operates continuously as follows:
This loop runs continuously to ensure real-time lighting control, with blinking patterns and safety interlocks maintained in the background.
Vehicle Lighting Control Application Architecture
The Analog Key Click outputs 0–3.3 V on a single analog line, with each button generating a specific voltage step. The ADC samples this voltage on ADC0_P0 (pin PTD1) at regular intervals and quantizes it into a digital code (a 12-bit ADC produces values between 0 and 4095). Each button corresponds to a specific value range, allowing six digital inputs to be read through a single ADC channel. ADC acquisition is the foundation of automotive sensing — used for switches, buttons, sensors, and many others.
Instead of using six separate GPIO pins, the Analog Key Click uses a resistor ladder that produces a different voltage for each button press. The application performs software debouncing (multiple ADC samples must agree before a press is confirmed) and then compares the ADC value against predefined thresholds to identify which button (T1–T6) was pressed. This technique is common in automotive steering-wheel controls, where many buttons share a single analog line to save wiring and pins.
FlexIO is a highly flexible peripheral on S32K3 that can emulate serial protocols like WS2812/NeoPixel. The RGB Click uses individually addressable LEDs that require precise timing (~800 kHz with strict pulse widths). FlexIO on PTA13 (FlexIO_D8) generates this waveform in hardware, without loading the CPU. Each of the 16 LEDs receives its color data through a serial stream, allowing independent control of color and brightness per LED.
The 16 LEDs of the RGB Click are logically grouped into automotive lighting zones:
The application implements safety logic typical of a real Body Control Module: high beam can only be activated when low beam is already ON; turning OFF the low beam automatically disables the high beam; hazard lights synchronize left and right turn signals simultaneously; high beam state is preserved during hazard blinking and restored between cycles. These interlocks illustrate how real automotive lighting logic prevents unsafe combinations and preserves driver intent.
Button press → analog voltage on shared line → ADC sample → software debouncing → button decoding → BCM logic (interlocks + dependencies) → FlexIO WS2812 output stream → RGB LED color update. This direct chain from the student's finger to the LEDs is the main educational value of the demo.
Required Hardware
| Component | Image | Purpose |
|---|---|---|
| FRDM-A-S32K312 |
Alternative MCU platform used to run the lighting application and process user inputs.
|
|
| FRDM-A-S32K344 |
Alternative MCU platform used to run the lighting application and control connected peripherals.
|
|
| FRDM-K64 Click Shield |
mikroBUS expansion board used to connect Click modules to the FRDM platform.
|
|
| Analog Key Click |
Six-button analog module used to simulate the vehicle lighting controls (headlights, indicators, brakes, hazards).
|
|
| 4x4 RGB Click |
16-LED RGB matrix used to display the automotive lighting patterns in real time.
|
|
| USB-C / 12 V supply | — |
Provides power and enables programming and debugging of the system through a single USB-C connection.
|
The example applications demonstrate how these peripherals are connected to the MCU pins and used to simulate a complete vehicle lighting control system.
| Vehicle Lighting Control on FRDM-A-S32K312 | Vehicle Lighting Control on FRDM-A-S32K344 |
|---|---|
S32 Design Studio IDE
S32K3 Automotive Software Package
Application Code Hub project import
| Step | Action | Sub-steps | Expected Result |
|---|---|---|---|
| 1 | Import the Project |
|
Project successfully appears in workspace |
| 2 | Build the Application |
|
Build completes with no errors and generates .elf file |
| 3 | Connect Hardware |
|
Board is powered and detected by IDE |
| 4 | Flash and Run |
|
Application runs continuously; LEDs perform startup test sequence |
| 5 | Functional Validation |
|
RGB LEDs display the correct automotive lighting patterns for each button |
| Issue | Possible Actions |
|---|---|
| Board Not Detected |
|
| No LEDs Lighting Up |
|
| Buttons Not Detected |
|
| Wrong Button Triggered |
|
| Incorrect LED Colors or Timing |
|
| High Beam Not Activating |
|
The basic implementation can be extended in several ways:
Additional Lighting Functions
Add fog lights, parking lights, or daytime running lights (DRL)
Simulate reverse lights that activate when a specific input is triggered
Adaptive Front Lighting
Integrate a steering angle input (e.g., POT Click) to swivel the headlights
Simulate cornering lights that turn on when indicators are active
Ambient Light Sensing
Add a light sensor to automatically enable low beams at dusk
Implement smooth dimming between day and night modes
Brake Light Enhancements
Add an emergency brake flashing pattern for hard braking
Implement a third brake light (single LED, always ON with brakes)
CAN Communication
Enable communication with other vehicle ECUs (e.g., BCM master, doors)
Receive lighting commands over the vehicle network
State Machine Implementation A more advanced approach is to implement a formal state machine covering:
Off
DRL / Parking
Low Beam
High Beam
Hazard / Fault
This example reflects key automotive principles:
Continuous monitoring of driver input
Immediate response to control signals
Reliable actuator (LED) control with predictable timing
Safety interlocks between lighting functions (high beam requires low beam)
In real systems:
Redundancy is required for safety-relevant functions (e.g., brake lights, hazards)
Fault detection mechanisms are implemented (open lamp, short circuit, overcurrent)
Systems must comply with ISO 26262 (functional safety standard)
Vehicle lighting is one of the most safety-critical automotive functions because it directly affects driver visibility and vehicle conspicuity. Modern Body Control Modules implement extensive diagnostics, backup lighting strategies, and fail-safe defaults (e.g., hazard lights activated on power-loss recovery).
This module demonstrates how a simple embedded system can implement complete vehicle lighting control using ADC input and FlexIO output on the S32K3 platform.
It shows how:
Multiple digital inputs can share a single analog line through resistor-ladder decoding
Analog data is acquired, debounced and processed in real time
Complex automotive lighting patterns are controlled through FlexIO-driven WS2812 LEDs
Safety interlocks and background blinking patterns are managed by BCM-style logic
| Result on FRDM-A-S32K312 | Result on FRDM-A-S32K344 |
|---|---|
The course provides a strong foundation for more advanced systems, including adaptive lighting, CAN networking, ambient sensing, and safety-oriented designs typical of automotive body-control modules.