Reference > Brix for Arduino
2.02.004 - Train Traffic Lights
![]() Description
Brick 2.02.004 is twin LED traffic light. It has 3 studs at the back so that it mounted onto LEGO® beams.
It's intended to be used on as traffic light (vertical) or level crossing light (horizontal).
Specifications
Pinout
The train traffic light has a cable with a 3 pin connector:
![]() Operation
The light contains current limiting resistors so you can connect it directly to your Arduino board.
The two LEDs can be controlled independently; the red wire powers the bottom light, the yellow wire powers the top light.
Example - Wiring
Example - Code
The following Arduino code will blink both lights in anti-phase at 1 Hz; each LED will blink once every second.
//-------------------------------------------------------------------------------------------------- // demo-2-02-004.ino // // Description: Demo to control a 4DBrix 2.02.004 train traffic light. // // Author: Lowa // Created: 28-Feb-2018 // Copyright (C) 2018, 4DBrix LLC. All rights reserved. // // Please feel free to use this example for personal, non-commercial use only, provided you keep the // copyright message intact. Have fun! //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- // Global variables //-------------------------------------------------------------------------------------------------- int LEDPin1; // The control pin for the bottom LED int LEDPin2; // The control pin for the top LED int LED; // Status indicating which LED is on int interval; // The blinking interval in milliseconds //-------------------------------------------------------------------------------------------------- // Initialization process //-------------------------------------------------------------------------------------------------- void setup() { // Configure the LED pins LEDPin1 = 3; LEDPin2 = 5; pinMode(LEDPin1, OUTPUT); // Define LEDPin1 as an output pin pinMode(LEDPin2, OUTPUT); // Define LEDPin2 as an output pin LED = 1; // Start with the bottom LED on interval = 1000; // Blink the lights once every 1000 ms; 500ms on and 500ms off } //-------------------------------------------------------------------------------------------------- // Processing loop //-------------------------------------------------------------------------------------------------- void loop() { // Switch the LEDs on/off if (LED == 1) { digitalWrite(LEDPin1, HIGH); digitalWrite(LEDPin2, LOW); LED = 2; } else { digitalWrite(LEDPin1, LOW); digitalWrite(LEDPin2, HIGH); LED = 1; } // Wait delay(interval/2); } //--- End-of-File----------------------------------------------------------------------------------- |