Halloween 2019 - Der Kürbis erwacht wieder - AZ-Delivery

 

Hallo AZ-Community,

 

die Tage werden kürzer, die Nächte länger, die Bäume ziehen Ihr Herbstkostüm an.

Es ist die Zeit der Ernte und des Blätterfalls. Und pünktlich am 31. Oktober feiern viele die Amerikanisierte Version des Irischen "All Hallows’ Eve" - besser bekannt als "Halloween".

In diesem Jahr haben wir keine Kosten und Mühen gescheut, und in penibelster Handarbeit einen echten Kürbis ausgehöhlt, und so lange daran herumgeschnitzt, bis er unserem Ton-Kürbis-Kopf aus dem letzten Jahr zum verwechseln ähnlich sieht. ;)

Diesen haben wir mit einem RGB-LED-Ring ausgestattet, welcher das Flackern einer kleinen, warmen Flamme simulieren soll.

Desweiteren haben wir einen Infrarot-Bewegungsmelder angeschlossen. Sollte sich nun jemand dem Kürbis näheren, sollen die Farben für einige Sekunden von einem gemütlichen Rot/Gelb-Ton auf einen unnatürlich-gruseligen Blauton wechseln.

Für die Umsetzung benötigen wir folgende Teile:

1x AZ-Delivery Nano V3 (Link zum Shop)
1x AZ-Delivery RGB LED Ring (Link zum Shop)
1x AZ-Delivery PIR Bewegungsmelder (Link zum Shop)

🎃🎃🎃 Alle 3 oben gelisteten Bauteile bieten wir für kurze Zeit auch als Set zum Sonderpreis an. (unser Halloween Spar-Angebot im Shop) 🎃🎃🎃

1x Ausreichend dimensioniertes 5V Netzteil
1x Elektrolyt Kondensator 1000 µF

 

Hier die Verbindungen:

Nano V3 RGB Ring PIR Sensor Nethteil Elko
VIN VIN VIN + +
GND GND GND - -
D5 DIN
D4 OUT

 

Nachdem alle Verbindungen hergestellt wurden, fehlt noch der Code den wir auf unseren Nano V3 hochladen müssen. Damit dieser Funktioniert, muss die FastLED Bibliothek installiert sein. (Link zur FastLED GitHub Seite)

 

#include <FastLED.h>

#define LED_PIN     5
#define COLOR_ORDER GRB
#define CHIPSET     WS2812B
#define NUM_LEDS    12

#define BRIGHTNESS  64
#define FRAMES_PER_SECOND 60

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];

// Fire2012 with programmable Color Palette
//
// This code is the same fire simulation as the original "Fire2012",
// but each heat cell's temperature is translated to color through a FastLED
// programmable color palette, instead of through the "HeatColor(...)" function.
//
// Four different static color palettes are provided here, plus one dynamic one.
//
// The three static ones are:
//   1. the FastLED built-in HeatColors_p -- this is the default, and it looks
//      pretty much exactly like the original Fire2012.
//
//  To use any of the other palettes below, just "uncomment" the corresponding code.
//
//   2. a gradient from black to red to yellow to white, which is
//      visually similar to the HeatColors_p, and helps to illustrate
//      what the 'heat colors' palette is actually doing,
//   3. a similar gradient, but in blue colors rather than red ones,
//      i.e. from black to blue to aqua to white, which results in
//      an "icy blue" fire effect,
//   4. a simplified three-step gradient, from black to red to white, just to show
//      that these gradients need not have four components; two or
//      three are possible, too, even if they don't look quite as nice for fire.
//
// The dynamic palette shows how you can change the basic 'hue' of the
// color palette every time through the loop, producing "rainbow fire".

CRGBPalette16 gPal;

void setup() {
  pinMode (4, INPUT);
  delay(3000); // sanity delay
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness( BRIGHTNESS );

  // This first palette is the basic 'black body radiation' colors,
  // which run from black to red to bright yellow to white.
  gPal = HeatColors_p;

  // These are other ways to set up the color palette for the 'fire'.
  // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
  //   gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White);

  // Second, this palette is like the heat colors, but blue/aqua instead of red/yellow
  //   gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua,  CRGB::White);

  // Third, here's a simpler, three-step gradient, from black to red to white
  //   gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::White);

}

void loop()
{
  if (!digitalRead(4)) {
    gPal = HeatColors_p;
  } else {
    gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua,  CRGB::White);
  }
  // Add entropy to random number generator; we use a lot of it.
  random16_add_entropy( random());

  // Fourth, the most sophisticated: this one sets up a new palette every
  // time through the loop, based on a hue that changes every time.
  // The palette is a gradient from black, to a dark color based on the hue,
  // to a light color based on the hue, to white.
  //
  //   static uint8_t hue = 0;
  //   hue++;
  //   CRGB darkcolor  = CHSV(hue,255,192); // pure hue, three-quarters brightness
  //   CRGB lightcolor = CHSV(hue,128,255); // half 'whitened', full brightness
  //   gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB::White);


  Fire2012WithPalette(); // run simulation frame, using palette colors

  FastLED.show(); // display this frame
  FastLED.delay(1000 / FRAMES_PER_SECOND);
}


// Fire2012 by Mark Kriegsman, July 2012
// as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
////
// This basic one-dimensional 'fire' simulation works roughly as follows:
// There's a underlying array of 'heat' cells, that model the temperature
// at each point along the line.  Every cycle through the simulation,
// four steps are performed:
//  1) All cells cool down a little bit, losing heat to the air
//  2) The heat from each cell drifts 'up' and diffuses a little
//  3) Sometimes randomly new 'sparks' of heat are added at the bottom
//  4) The heat from each cell is rendered as a color into the leds array
//     The heat-to-color mapping uses a black-body radiation approximation.
//
// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
//
// This simulation scales it self a bit depending on NUM_LEDS; it should look
// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
//
// I recommend running this simulation at anywhere from 30-100 frames per second,
// meaning an interframe delay of about 10-35 milliseconds.
//
// Looks best on a high-density LED setup (60+ pixels/meter).
//
//
// There are two main parameters you can play with to control the look and
// feel of your fire: COOLING (used in step 1 above), and SPARKING (used
// in step 3 above).
//
// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames.  More cooling = shorter flames.
// Default 55, suggested range 20-100
#define COOLING  55

// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire.  Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 120


void Fire2012WithPalette()
{
  // Array of temperature readings at each simulation cell
  static byte heat[NUM_LEDS];

  // Step 1.  Cool down every cell a little
  for ( int i = 0; i < NUM_LEDS; i++) {
    heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  }

  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for ( int k = NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  }

  // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  if ( random8() < SPARKING ) {
    int y = random8(7);
    heat[y] = qadd8( heat[y], random8(160, 255) );
  }

  // Step 4.  Map from heat cells to LED colors
  for ( int j = 0; j < NUM_LEDS; j++) {
    // Scale the heat value from 0-255 down to 0-240
    // for best results with color palettes.
    byte colorindex = scale8( heat[j], 240);
    CRGB color = ColorFromPalette( gPal, colorindex);
    int pixelnumber;
    if ( gReverseDirection ) {
      pixelnumber = (NUM_LEDS - 1) - j;
    } else {
      pixelnumber = j;
    }
    leds[pixelnumber] = color;
  }
}

 

Über die 2 Potis am Bewegungssensor können wir einstellen wie empfindlich der Sensor reagiert, und wie Lange der Ausgangspin das HIGH Signal ausgibt.

 

Der Kürbis leuchtet Rot bis Orange:

Kürbis mit normalen farben.

Sobald eine Bewegung festgestellt wird, wechselt die Farbe auf Blau:

Unnatürlich blaues Licht.

 

 

Natürlich sind auch andere Farben möglich. Wir sind schon gespannt auf eure schaurigen Kreationen.

 

Wir wünschen euch viel Spaß beim nachbauen, und verabschieden uns bis zum nächsten Beitrag.

Euer Moritz Spanger

Nachtrag: 2 Fehler im Quellcode korrigiert. Danke an Heiko Schütz für den Hinweis 👍

Für arduinoSpecials

23 Kommentare

Kommentar hinterlassen

Alle Kommentare werden von einem Moderator vor der Veröffentlichung überprüft

Empfohlene Blogbeiträge

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery