The SWTbahn platforms use lanterns to indicate the current positions of the servo-driven points. A lantern has constant brightness if its associated point is in the normal position, and has pulsing brightness if its point is in the reverse position. The pulsing effect of all lanterns are synchronised via a synchronisation pulse generated from the OneControl boards.
The SWTbahn Standard uses an ATtiny84A to control the lantern LED (powered from the OneControl GPIO ports), while the SWTbahn Full uses an Adafruit Metro Mini (powered externally by a 5V supply).
- Programmer for the ATtiny: STK500
- Arduino IDE
- ATtiny board support for Arduino
- Open the Arduino IDE
- Go to the settings and add the following board manager URL: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
- Go to Tools > Boards > Board Manager
- Search for "attiny" by David A. Mellis and install the board support package
- Open
attiny84a.ino
in Arduino IDE - Plug the STK500 programmer into the computer, and record the serial port it has been assigned
- Select Tools in the menu bar and configure the following settings:
- Board: ATtiny/24/48/84
- Processor: ATtiny84
- Clock: Internal 8 MHz
- Port: Whichever port the programmer has been assigned
- Programmer: Atmel STK500 development board
- Plug the STK500 programmer to the ATtiny84A
- Compile and upload to the ATtiny84A
- Download and install the USB serial drivers
- Open
adafruit-metro-mini.ino
in Arduino IDE - Plug the Adafruit Metro Mini into a USB port of your computer, and record the serial port it has been assigned
- Select Tools in the menu bar and configure the following settings:
- Board: Arduino UNO
- Port: Whichever port the programmer has been assigned
- Programmer: USBtinyISP
- Compile and upload to the Adafruit Metro Mini
Interrupt for the synchronisation pulse pin (see Datasheet p. 50)
GIMSK = (1 << PCIE1); // Pin Change Interrupt Enable 1
GIFR = (1 << PCIF1); // Pin Change Interrupt Flag 1
PCMSK1 = (1 << SYNC_INT); //Pin Change Enable Mask 9
PWM for the glowing effect (see Datasheet p. 85)
// Timer/Counter 1 at 800
TCCR1A = 0; // Clear register TCCR1A
TCCR1B = 0; // Clear register TCCR1B
TCNT1 = 0; // Reset counter value
// Set compare match register for 600Hz increments
OCR1A = 40; // = 8MHz/(3kHz*64 prescaler) - 1, (OCR0A value must be less than 65536)
TCCR1B |= (1 << WGM12); // Enable Clear Timer on Capture mode
TCCR1B |= (1 << CS11) | (1 << CS10); // Prescaler of 64
TIMSK1 |= (1 << OCIE1A); // Enable timer compare interrupt