Blinklicht / Dachblitzer per Arduino

Tach zusammen,

ich baue für mein RC-Car gerade eine Lichtsteuerung.

Per Handsender kann ich verschiedenen Dinge schalten.
Soweit funktioniert erstmal alles ... die Signale vom Empfänger-Kanal kommen an und ich kann sie verarbeiten.

Jetzt soll unter anderem auf dem Dach des Autos ein Blitzlicht montiert werden.
Ihr könnte es Euch wie bei Ami-Cops vorstellen ... Eine Lichtbar mit Wechsel-Blitzblinken.
Allerdings soll es in meinem Fall nicht rot-blau sein, sondern gelb ... also ein Transporter-Warn-Blitz-Lichtbalken :slight_smile:

Ungefähr so ... nur eben gelb ...:

Ich habe bereits die Dachleiste mit RGB-LEDs ausgerüstet und steuer sie bereits an.
Es soll mehrere Programme geben ... eins eben diese Gelb-Sequenz.

Die Frage ist nun, gibt es für NEOPIXELS für sowas irgendwas vorgefertigtes, oder fange ich an per Pausen-AN-AUS mir mein eigenes Blitzgewitter zu programmieren?

Wäre für Hilfe dankbar.

Danke
Cappy

Hier gibt es Beispiele (z.B. Strobe Effect), die Du selbst weiter ausbauen kannst.

Es gibt auch einen Generator, der (delay()-freien!) Arduino-Code ausspuckt.

Nabend,

ich habe mir beides mal angesehenm, vielen Dank.
Ich glaube das Erste (STROBE) ist das was ich suche.

Alleridngs kann man da scheinbar nur den ganzen Strip blitzen lassen, oder?
Ich würde das gerne in zwei bereiche teilen, die wechselnd stroben!?

Cappy

du kannst den Strip in so viele logische Abschnitte teilen wie du magst.

hier ein Beispiel mit einzelnen Blinkern, Lichtern und einem Lauflicht.
Einfach eine Klasse machen, die eine Referenz auf dein Strip Objekt nimmt:

/*
  Use pixels in a strip as separate objects
  by noiasca

  2020-03-02 https://forum.arduino.cc/index.php?topic=668289.15 
  https://forum.arduino.cc/index.php?topic=668125
  2020-12-31 https://forum.arduino.cc/index.php?topic=720583.0
*/

const byte ledPin = 2;                // Which pin on the Arduino is connected to the NeoPixels?
const uint16_t ledCount = 8;

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip(ledCount, ledPin, NEO_GRB + NEO_KHZ800);

class BlinkLed {
  private:
    byte state = 1;       // 0 off, 1 blink high , 2 blink low
    unsigned long previousMillis;
    uint16_t on = 180;
    uint16_t off = 320;   // 180/320 is according ECE
    uint32_t colorOn = 0xAA0000;
    uint32_t colorOff = 0x000000;
    Adafruit_NeoPixel& obj;
    const byte id;

  public:
    BlinkLed(Adafruit_NeoPixel& obj, byte id):
      obj(obj),
      id(id)
    {}

    void set(uint16_t _on, uint16_t _off)  // modify on/off times during runtime
    {
      on = _on;
      off = _off;
    }

    void setState(byte _state)            // 0 switch off blinking; 1 Switch on blinking;
    {
      state = _state;
    }

    void setColor(uint32_t newColorOn, uint32_t newColorOff)
    {
      colorOn = newColorOn;
      colorOff = newColorOff;
    }

    void tick()
    {
      if (state)
      {
        uint32_t currentMillis = millis();
        if (state == 1 && currentMillis - previousMillis >= on) {
          // save the last time you blinked the LED
          obj.setPixelColor(id, colorOn);
          obj.show();
          state = 2;
          previousMillis = currentMillis;
        }
        if (state == 2 && currentMillis - previousMillis >= off) {
          // save the last time you blinked the LED
          obj.setPixelColor(id, colorOff);
          obj.show();
          state = 1;
          previousMillis = currentMillis;
        }
      }
    }
};


class Scanner {
  private:
    byte state = 1;       // 0 off, 1 blink high , 2 blink low
    unsigned long previousMillis;
    uint16_t on = 200;
    uint32_t colorOn = 0xAA0000;
    uint32_t colorOff = 0x000000;
    int8_t direction = 1;     // direction
    Adafruit_NeoPixel& obj;
    const byte id;            // first pixel of this group
    const byte leds;          // how many leds

  public:
    Scanner(Adafruit_NeoPixel& obj, byte id, byte leds):
      obj(obj),
      id(id),
      leds(leds)
    {}

    void set(uint16_t _on)  // modify on/off times during runtime
    {
      on = _on;
    }

    void setState(byte _state)            // 0 switch off blinking; 1 Switch on blinking;
    {
      state = _state;
    }

    void setColor(uint32_t newColorOn, uint32_t newColorOff)
    {
      colorOn = newColorOn;
      colorOff = newColorOff;
    }

    void tick()
    {
      if (state)
      {
        uint32_t currentMillis = millis();
        if (currentMillis - previousMillis >= on) {
          // save the last time you blinked the LED
          Serial.println(state);
          obj.setPixelColor(id + state - 1, colorOff);
          state = state + direction;
          if (state > leds) {
            state = leds - 1;
            direction = -1;
          }
          else if (state < 1)
          {
            state = 2;
            direction = 1;
          }
          obj.setPixelColor(id + state - 1, colorOn);
          obj.show();
          previousMillis = currentMillis;
        }
      }
    }
};

BlinkLed turnsignalLeft(strip, 0);       // name of strip object, pixelId in strip
BlinkLed blinkLedFront(strip, 1);        // name of strip object, pixelId in strip
BlinkLed blinkLedRear(strip, 6);         // name of strip object, pixelId in strip
BlinkLed turnsignalRight(strip, 7);      // name of strip object, pixelId in strip

Scanner scanner(strip, 2, 4);            // name of strip object, first pixelId, number of pixels for this group

void setup() {
  Serial.begin(115200);
  Serial.println(F("\nStart"));

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(127); // Set BRIGHTNESS to about 1/5 (max = 255)

  blinkLedFront.setColor(0x0000AA, 0x555533);    // blink blue/white

  blinkLedRear.setColor(0x0000AA, 0xFF0000);     // blink blue/red
  blinkLedRear.set(400, 200);

  turnsignalRight.setColor(0xFF8000, 0x201000);
  turnsignalRight.set(666, 666);                    // 1,5Hz +/-0,5Hz 30 % to 80 %

  turnsignalLeft.setColor(0xFF8000, 0x201000);
  turnsignalLeft.set(666, 666);                    // 1,5Hz +/-0,5Hz 30 % to 80 %
  turnsignalLeft.setState(0);                      // switch off
}

void loop() {
  blinkLedFront.tick();
  blinkLedRear.tick();
  scanner.tick();
  turnsignalRight.tick();
  turnsignalLeft.tick();  // is turned off, therefore not shown
}

Ausprobieren, code studieren!

noiasca:
Ausprobieren, code studieren!

... danach auf eigenes Setup anpassen, wieder ausprobieren und dann mit konkreter Frage gerne wiederkommen

Nabend,

ich probiere gerade schon rum, aber so ich blicke es noch gar nicht, ehrlich gesagt.
Mit Klassen komme ich auch nicht zurecht :-/

Cappy

Dann mache ich mal einen Versuch, getestet mit UNO:

#include <FastLED.h>

FASTLED_USING_NAMESPACE

#define DATA_PIN    11
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS    8
CRGB leds[NUM_LEDS];

uint32_t jetzt;
bool neu = true;

void setup() {
  // tell FastLED about the LED strip configuration
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
}

void loop()
{
  jetzt = millis();
  animation();
}

void animation() {
  static byte schritt = 0;
  switch (schritt) {
    case 0:
    case 2:
      if (gelbpuls(1, 1, 100)) schritt++;
      break;
    case 1:
    case 3:
      if (gelbpuls(1, 0, 100)) schritt++;
      break;
    case 4:
    case 6:
      if (gelbpuls(0, 1, 100)) schritt++;
      break;
    case 5:
    case 7:
      if (gelbpuls(0, 0, 100)) schritt++;
      break;
    default:
      schritt = 0;
  }
  if (neu) {
    FastLED.show(); // send the 'leds' array out to the actual LED strip
    neu = false;
  }
}

bool gelbpuls(bool links, bool an, uint32_t intervall) {
  bool fertig = false;
  static uint32_t vorhin = jetzt;
  if (jetzt - vorhin >= intervall) {
    vorhin = jetzt;
    if (an) {
      if (links) {
        for (byte j = 0; j < NUM_LEDS / 2; j++) {
          leds[j] = CHSV( 64, 255, 255);
        }
      } else {
        for (byte j = NUM_LEDS / 2; j < NUM_LEDS; j++) {
          leds[j] = CHSV( 64, 255, 255);
        }
      }
    } else {
      for (byte j = 0; j < NUM_LEDS; j++) {
        leds[j] = CRGB(0, 0, 0);
      }
    }
    neu = true;
    fertig = true;
  }
  return fertig;
}