Blaulicht-Simulationen

Blaulicht / Rundumkennleuchte
Abb.: Rundumkennleuchte ("Blaulicht")

"Blaulichter" (d.h. Kennleuchten bzw. Rundumkennleuchten) können z.B. für den Modellbau leicht mit einem Mikrocontroller und einer oder ein paar LEDs simuliert werden.

Kennleuchten/Blaulicht mit Arduino

Zunächst werden verschiedene Leuchtmuster mit dem Arduino als Prototypen gebaut und programmiert.

Verwendete Bauteile

Aufbau

Aufbau auf dem Breadboard
Abb.: Aufbau auf dem Breadboard

Sketches

Einfaches Blinken

/**
 * Simulating emergency flashing lights (5 LEDs are needed for this)
 */

#define PIN_LED_1   8
#define PIN_LED_2   9
#define PIN_LED_3  10
#define PIN_LED_4  11
#define PIN_LED_5  12

#define FLASH_DELAY 300

byte leds[5] = {PIN_LED_1, PIN_LED_2, PIN_LED_3, PIN_LED_4, PIN_LED_5};
byte ledStatus[5];

void setup()
{
    for(byte i=0; i<sizeof(leds); i++) {
        ledStatus[i] = LOW;
        pinMode(leds[i], OUTPUT);
    }
}

void loop()
{
    showLeds();
    for(byte i=0; i<sizeof(leds); i++) {
        if (ledStatus[i] == HIGH) {
            ledStatus[i] = LOW;
        } else {
            ledStatus[i] = HIGH;
        }
    }
    delay(FLASH_DELAY);
}

void showLeds()
{
    for(byte i=0; i<sizeof(leds); i++) {
        digitalWrite(leds[i], ledStatus[i]);
    }
}

Doppeltes Blinken

/**
 * Simulating emergency flashing lights (2 LEDs are needed for this)
 */

#define PIN_LED_1   8
#define PIN_LED_2   9

#define BLINK_DELAY 350

byte leds[2] = {PIN_LED_1, PIN_LED_2};
byte activeLed;

void setup()
{
    for(byte i=0; i<sizeof(leds); i++) {
        pinMode(leds[i], OUTPUT);
        activeLed = 0;
    }
}

void loop()
{
    showLeds();
    activeLed++;
    activeLed %= sizeof(leds);
    delay(BLINK_DELAY);
}

void showLeds()
{
    for(byte i=0; i<sizeof(leds); i++) {
        if (activeLed == i) {
            digitalWrite(leds[i], HIGH);
        } else {
            digitalWrite(leds[i], LOW);
        }
    }
}

Alternatives Blitzen

/**
 * Simulating emergency flashing lights (2 LEDs are needed for this)
 */

#define PIN_LED_1   8
#define PIN_LED_2   9

#define FLASH_DELAY 40
#define PAUSE_DELAY 500
#define FLASH_TIMES 4

byte leds[2] = {PIN_LED_1, PIN_LED_2};
byte currentLed;

void setup()
{
    for(byte i=0; i<sizeof(leds); i++) {
        pinMode(leds[i], OUTPUT);
    }
    currentLed = 0;
}

void loop()
{
    currentLed++;
    currentLed %= sizeof(leds);
    for(byte i=0; i<FLASH_TIMES; i++) {
        flash(currentLed);
    }
    delay(PAUSE_DELAY);
}

void flash(byte ledIndex)
{
    digitalWrite(leds[ledIndex], HIGH);
    delay(FLASH_DELAY);
    digitalWrite(leds[ledIndex], LOW);
    delay(FLASH_DELAY);
}

Mehrfaches Blitzen

/**
 * Simulating emergency flashing lights (5 LEDs are needed for this)
 */

#define PIN_LED_1   8
#define PIN_LED_2   9
#define PIN_LED_3  10
#define PIN_LED_4  11
#define PIN_LED_5  12

#define FLASH_DELAY 40
#define PAUSE_DELAY 500
#define FLASH_TIMES 4

byte leds[5] = {PIN_LED_1, PIN_LED_2, PIN_LED_3, PIN_LED_4, PIN_LED_5};
byte ledStatus[5];

void setup()
{
    for(byte i=0; i<sizeof(leds); i++) {
        ledStatus[i] = LOW;
        pinMode(leds[i], OUTPUT);
        digitalWrite(leds[i], ledStatus[i]);
    }
}

void loop()
{
    for(byte i=0; i<FLASH_TIMES; i++) {
        flash();
    }
    delay(PAUSE_DELAY);
}

void flash()
{
    for(byte i=0; i<sizeof(leds); i++) {
        digitalWrite(leds[i], HIGH);
    }
    delay(FLASH_DELAY);
    for(byte i=0; i<sizeof(leds); i++) {
        digitalWrite(leds[i], LOW);
    }
    delay(FLASH_DELAY);
}

Rotierendes Licht

/**
 * Simulating emergency rotating lights (5 LEDs are needed for this)
 */

#define PIN_LED_1   8
#define PIN_LED_2   9
#define PIN_LED_3  10
#define PIN_LED_4  11
#define PIN_LED_5  12

#define ROTATE_DELAY 100

byte leds[5] = {PIN_LED_1, PIN_LED_2, PIN_LED_3, PIN_LED_4, PIN_LED_5};
byte activeLed;

void setup()
{
    for(byte i=0; i<sizeof(leds); i++) {
        pinMode(leds[i], OUTPUT);
        activeLed = 0;
    }
}

void loop()
{
    showLeds();
    activeLed++;
    activeLed %= sizeof(leds);
    delay(ROTATE_DELAY);
}

void showLeds()
{
    for(byte i=0; i<sizeof(leds); i++) {
        if (activeLed == i) {
            digitalWrite(leds[i], HIGH);
        } else {
            digitalWrite(leds[i], LOW);
        }
    }
}
zurück