#include <FastLED.h>
const byte REDPIN = 5;
const byte GREENPIN = 3;
const byte BLUEPIN = 6;
const byte SMOKEPIN = 13;
#define DATA_PIN 4
#define NUM_LEDS 9
CRGB leds[NUM_LEDS];
void showAnalogRGB( const CRGB& rgb )
{
analogWrite(REDPIN, rgb.r );
analogWrite(GREENPIN, rgb.g );
analogWrite(BLUEPIN, rgb.b );
leds[0] = rgb;
FastLED.show();
}
void ausgabeRGB( const CRGB& rgb, const uint8_t hue )
{
static uint8_t alt_hue = hue;
static bool ausgabe = true;
if (hue < alt_hue) ausgabe = false;
if (ausgabe)
{
char buf[100] = {'\0'};
snprintf(buf, sizeof(buf), "hue=%d\tR=%d\tG=%d\tB=%d\n", hue, rgb.r, rgb.g, rgb.b);
Serial.print(buf);
}
alt_hue = hue;
}
void setup() {
Serial.begin(9600);
Serial.println("\nStart");
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
FastLED.show();
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
pinMode(SMOKEPIN, OUTPUT);
}
void loop()
{
glut();
rauch();
}
void glut() {
uint32_t jetzt = millis();
static uint32_t vorhin = 0;
const uint32_t intervall = 20;
const uint8_t FARBE_MAX = 64;
const uint8_t FARBE_MIN = 0;
static uint8_t hue = FARBE_MIN;
static int8_t delta = 0;
if (jetzt - vorhin >= intervall)
{
vorhin = jetzt;
hue = hue + delta;
if (hue >= FARBE_MAX) delta = -1;
if (hue <= FARBE_MIN) delta = 1;
// Use FastLED automatic HSV->RGB conversion
showAnalogRGB( CHSV( hue, 255, 255) );
ausgabeRGB( CHSV( hue, 255, 255), hue );
}
}
void rauch()
{
uint32_t jetzt = millis();
static uint32_t vorhin = 0;
static uint32_t intervall = 0;
static bool ausEIN = false;
if (jetzt - vorhin >= intervall)
{
vorhin = jetzt;
if (ausEIN)
{
intervall = 100;
} else {
intervall = 2000;
}
digitalWrite(SMOKEPIN, ausEIN);
ausEIN = !ausEIN;
}
}