arduino:silentbase_802_neopixel:programmversion_4
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
arduino:silentbase_802_neopixel:programmversion_4 [18.03.2023 19:45] – angelegt Frickelpiet | arduino:silentbase_802_neopixel:programmversion_4 [18.05.2023 12:34] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== | + | ====== |
Nachdem in [[arduino: | Nachdem in [[arduino: | ||
+ | < | ||
+ | // Beleuchtung BeQuiet SilentBase 802 | ||
+ | // Arduino Nano (Every) | ||
+ | // | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // Debug-Level | ||
+ | //#define DEBUG_EFFECT | ||
+ | //#define DEBUG_SENSOR | ||
+ | |||
+ | // | ||
+ | #define NEOPIN1 | ||
+ | #define NEOPIN2 | ||
+ | #define POWERPIN | ||
+ | #define LEDPIN1 | ||
+ | #define LEDPIN2 | ||
+ | #define ONE_WIRE_BUS 11 // Datenleitung für die Temperatursensoren DS18B20 | ||
+ | |||
+ | // | ||
+ | #define COLOR_ORDER GRB | ||
+ | #define CHIPSET | ||
+ | #define NUM_LEDS | ||
+ | #define BRIGHTNESS | ||
+ | |||
+ | // | ||
+ | // 9 bit resolution: 0,5°C increments, takes 94 ms for A/D conversion | ||
+ | // 10 bit resolution: 0,25°C increments, takes 188 ms for A/D conversion | ||
+ | // 11 bit resolution: 0,125°C increments, takes 375 ms for A/D conversion | ||
+ | // 12 bit resolution: 0,0625°C increments, takes 750 ms for A/D conversion | ||
+ | #define TEMPERATURE_PRECISION 11 | ||
+ | |||
+ | // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/ | ||
+ | OneWire oneWire(ONE_WIRE_BUS); | ||
+ | |||
+ | // Pass our oneWire reference to Dallas Temperature. | ||
+ | DallasTemperature sensors(& | ||
+ | |||
+ | // arrays to hold device addresses | ||
+ | DeviceAddress sensor0, sensor1, sensor2; | ||
+ | |||
+ | // Definiert die Variablen | ||
+ | bool gReverseDirection = true; // Kehrt den Effekt um, wenn wahr | ||
+ | |||
+ | float temperature; | ||
+ | float temperature_min = 20; // Konfiguriert den unteren Grenzwert der Gehäusetemperatur | ||
+ | float temperature_max = 40; // Konfiguriert den oberen Grenzwert der Gehäusetemperatur | ||
+ | |||
+ | boolean LEDstate; | ||
+ | boolean POWERstate = 0; // Wird " | ||
+ | |||
+ | int cooling; | ||
+ | int sparking; | ||
+ | static byte heat[71]; | ||
+ | | ||
+ | // Definiert die NeoPixel-Strips | ||
+ | CRGB strip[NUM_LEDS]; | ||
+ | |||
+ | // Fire2012 with programmable Color Palette | ||
+ | // | ||
+ | // This code is the same fire simulation as the original " | ||
+ | // but each heat cell's temperature is translated to color through a FastLED | ||
+ | // programmable color palette, instead of through the " | ||
+ | // | ||
+ | // 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 " | ||
+ | // | ||
+ | // 2. a gradient from black to red to yellow to white, which is | ||
+ | // visually similar to the HeatColors_p, | ||
+ | // what the 'heat colors' | ||
+ | // 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 ' | ||
+ | // color palette every time through the loop, producing " | ||
+ | |||
+ | CRGBPalette16 gPal; | ||
+ | |||
+ | // Definiert die Tracking-Variablen für die IF-Abfragen | ||
+ | unsigned long previousMillisSensors = 0; | ||
+ | unsigned long previousMillisLED = 0; | ||
+ | unsigned long previousMillisEffect = 0; | ||
+ | unsigned long previousMillisSerialPrint = 0; | ||
+ | |||
+ | // Definiert die Intervalle für die IF-Abfragen | ||
+ | int intervalSensors = 1000; // Delay für Auslesen der Temperatursensoren | ||
+ | int intervalLED = 500; // Delay für die Ausgabe der Temperatur als Blinkfrequenz der LED2 | ||
+ | int intervalEffect = 15; // Delay für Effekte | ||
+ | int intervalSerialPrint = 1000; // Delay für serielle Ausgabe | ||
+ | |||
+ | |||
+ | // | ||
+ | void setup() { | ||
+ | digitalWrite(POWERPIN, | ||
+ | Serial.begin(115200); | ||
+ | | ||
+ | // Initialisiere die Output-Pins | ||
+ | pinMode(NEOPIN1, | ||
+ | pinMode(NEOPIN2, | ||
+ | pinMode(POWERPIN, | ||
+ | pinMode(LEDPIN1, | ||
+ | pinMode(LEDPIN2, | ||
+ | | ||
+ | |||
+ | // Initialisiere die NeoPixel-Strips | ||
+ | digitalWrite(POWERPIN, | ||
+ | |||
+ | FastLED.addLeds< | ||
+ | FastLED.addLeds< | ||
+ | FastLED.setBrightness( BRIGHTNESS ); | ||
+ | | ||
+ | // This first palette is the basic 'black body radiation' | ||
+ | // 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 ' | ||
+ | // First, a gradient from black to red to yellow to white -- similar to HeatColors_p | ||
+ | // gPal = CRGBPalette16( CRGB:: | ||
+ | | ||
+ | // Second, this palette is like the heat colors, but blue/aqua instead of red/yellow | ||
+ | // gPal = CRGBPalette16( CRGB:: | ||
+ | | ||
+ | // Third, here's a simpler, three-step gradient, from black to red to white | ||
+ | // gPal = CRGBPalette16( CRGB:: | ||
+ | |||
+ | // Start up the sensor library | ||
+ | sensors.begin(); | ||
+ | |||
+ | // locate devices on the bus | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(sensors.getDeviceCount(), | ||
+ | Serial.println(" | ||
+ | |||
+ | // Search for devices on the bus and assign based on an index. Ideally, | ||
+ | // you would do this to initially discover addresses on the bus and then | ||
+ | // use those addresses and manually assign them (see above) once you know | ||
+ | // the devices on your bus (and assuming they don't change). | ||
+ | // | ||
+ | // method 1: by index | ||
+ | if (!sensors.getAddress(sensor0, | ||
+ | if (!sensors.getAddress(sensor1, | ||
+ | if (!sensors.getAddress(sensor2, | ||
+ | |||
+ | // show the addresses we found on the bus | ||
+ | Serial.print(" | ||
+ | printAddress(sensor0); | ||
+ | Serial.println(); | ||
+ | |||
+ | Serial.print(" | ||
+ | printAddress(sensor1); | ||
+ | Serial.println(); | ||
+ | |||
+ | Serial.print(" | ||
+ | printAddress(sensor2); | ||
+ | Serial.println(); | ||
+ | | ||
+ | // set the resolution to 11 bit per device | ||
+ | sensors.setResolution(sensor0, | ||
+ | sensors.setResolution(sensor1, | ||
+ | sensors.setResolution(sensor2, | ||
+ | |||
+ | #ifdef DEBUG_SENSOR | ||
+ | Serial.print(" | ||
+ | Serial.println(sensors.getResolution(sensor0), | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.println(sensors.getResolution(sensor1), | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.println(sensors.getResolution(sensor2), | ||
+ | #endif | ||
+ | | ||
+ | delay (2000); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | void loop() { | ||
+ | // Aktuelle Zeit abfragen | ||
+ | unsigned long currentMillis = millis(); | ||
+ | |||
+ | // Schaltet die NeoPixel ein und initialisiert die NeoPixel | ||
+ | if(POWERstate == 0) { | ||
+ | POWERstate = 1; | ||
+ | digitalWrite(LEDPIN1, | ||
+ | } | ||
+ | |||
+ | // Auslesen der Temperatursensoren und Berechnen einiger Variablen zur Beeinflussung des Effekts | ||
+ | if ((unsigned long)(currentMillis - previousMillisSensors) >= intervalSensors) { | ||
+ | | ||
+ | // Request to all devices on the bus | ||
+ | // | ||
+ | unsigned long start = micros(); | ||
+ | sensors.setWaitForConversion(false); | ||
+ | sensors.requestTemperatures(); | ||
+ | sensors.setWaitForConversion(true); | ||
+ | unsigned long stop = micros(); | ||
+ | | ||
+ | #ifdef DEBUG_SENSOR | ||
+ | Serial.print(" | ||
+ | Serial.print(stop - start); | ||
+ | Serial.println(" | ||
+ | |||
+ | // print the device information | ||
+ | printData(sensor0); | ||
+ | printData(sensor1); | ||
+ | printData(sensor2); | ||
+ | #endif | ||
+ | | ||
+ | // Berechnen der höchsten Temperatur an den verfügbaren Sensoren | ||
+ | float tempSensor0 = sensors.getTempC(sensor0); | ||
+ | float tempSensor1 = sensors.getTempC(sensor1); | ||
+ | float tempSensor2 = sensors.getTempC(sensor2); | ||
+ | temperature = max(tempSensor0, | ||
+ | temperature = max(temperature, | ||
+ | |||
+ | #ifdef DEBUG_SENSOR | ||
+ | Serial.print(" | ||
+ | Serial.print(temperature); | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | | ||
+ | // Berechenen der Blinkfrequenz von LED2 | ||
+ | constrain(temperature, | ||
+ | intervalLED = map(temperature, | ||
+ | #ifdef DEBUG_SENSOR | ||
+ | Serial.print(" | ||
+ | #endif | ||
+ | | ||
+ | // Berechnung von Cooling für den Effekt Fire 2012: Legt fest, wie stark die aufsteigenden Flammen abkühlen. | ||
+ | // Weniger Cooling = höhere Flammen, mehr Cooling = kürzere Flammen. | ||
+ | // Werte zwischen 20 und 100 sind empfohlen, ein guter Standard ist 55. | ||
+ | cooling = map(temperature, | ||
+ | |||
+ | // Berechnung von Sparking für den Effekt Fire2012: Legt fest, wie oft ein Funke auflohdert. | ||
+ | // Höhere Werte = stürmisches Feuer, niedrige Werte = ruhigeres Feuer. | ||
+ | // Werte zwischen 50 und 200 sind empfohlen, ein guter Standard ist 120. | ||
+ | sparking = map(temperature, | ||
+ | |||
+ | #ifdef DEBUG_SENSOR | ||
+ | // | ||
+ | Serial.print(cooling); | ||
+ | // | ||
+ | Serial.println(sparking); | ||
+ | #endif | ||
+ | | ||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisSensors = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | // Ausgabe der Temperatur als Blinkfrequenz der LED1 | ||
+ | if ((unsigned long)(currentMillis - previousMillisLED) >= intervalLED) { | ||
+ | |||
+ | if(LEDstate == 0) { | ||
+ | digitalWrite(LEDPIN2, | ||
+ | // | ||
+ | LEDstate = 1; | ||
+ | } | ||
+ | else if(LEDstate == 1) { | ||
+ | digitalWrite(LEDPIN2, | ||
+ | // | ||
+ | LEDstate = 0; | ||
+ | } | ||
+ | | ||
+ | | ||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisLED = currentMillis; | ||
+ | } | ||
+ | |||
+ | // Feuer-Effekt: | ||
+ | if ((unsigned long)(currentMillis - previousMillisEffect) >= intervalEffect) { | ||
+ | |||
+ | #ifdef DEBUG_EFFECT | ||
+ | unsigned long start = micros(); | ||
+ | #endif | ||
+ | | ||
+ | // Add entropy to random number generator; we use a lot of it. | ||
+ | random16_add_entropy( random()); | ||
+ | | ||
+ | // This basic one-dimensional ' | ||
+ | // There' | ||
+ | // 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 ' | ||
+ | // 3) Sometimes randomly new ' | ||
+ | // 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). | ||
+ | |||
+ | // Step 1. Cool down every cell a little | ||
+ | for( int i = 0; i < NUM_LEDS; i++) { | ||
+ | heat[i] = qsub8( heat[i], | ||
+ | } | ||
+ | | ||
+ | // Step 2. Heat from each cell drifts ' | ||
+ | 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 ' | ||
+ | if( random8() < sparking ) { | ||
+ | int y = random8(7); | ||
+ | heat[y] = qadd8( heat[y], random8(160, | ||
+ | } | ||
+ | |||
+ | // 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. | ||
+ | uint8_t colorindex = scale8( heat[j], 240); | ||
+ | CRGB color = ColorFromPalette( gPal, colorindex); | ||
+ | int pixelnumber; | ||
+ | if( gReverseDirection ) { | ||
+ | pixelnumber = (NUM_LEDS-1) - j; | ||
+ | } else { | ||
+ | pixelnumber = j; | ||
+ | } | ||
+ | strip[pixelnumber] = color; | ||
+ | // | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | | ||
+ | #ifdef DEBUG_EFFECT | ||
+ | unsigned long stop = micros(); | ||
+ | // Ausgabe der Zeit in Microsekunden, | ||
+ | // | ||
+ | Serial.println(stop - start); | ||
+ | // | ||
+ | #endif | ||
+ | | ||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisEffect = currentMillis; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // function to print a device address | ||
+ | void printAddress(DeviceAddress deviceAddress) | ||
+ | { | ||
+ | for (uint8_t i = 0; i < 8; i++) | ||
+ | { | ||
+ | // zero pad the address if necessary | ||
+ | if (deviceAddress[i] < 16) Serial.print(" | ||
+ | Serial.print(deviceAddress[i], | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // function to print the temperature for a device | ||
+ | void printTemperature(DeviceAddress deviceAddress) | ||
+ | { | ||
+ | float tempC = sensors.getTempC(deviceAddress); | ||
+ | Serial.print(" | ||
+ | Serial.print(tempC); | ||
+ | } | ||
+ | |||
+ | // function to print a device' | ||
+ | void printResolution(DeviceAddress deviceAddress) | ||
+ | { | ||
+ | Serial.print(" | ||
+ | Serial.print(sensors.getResolution(deviceAddress)); | ||
+ | Serial.println(); | ||
+ | } | ||
+ | |||
+ | // main function to print information about a device | ||
+ | void printData(DeviceAddress deviceAddress) | ||
+ | { | ||
+ | Serial.print(" | ||
+ | printAddress(deviceAddress); | ||
+ | Serial.print(" | ||
+ | printTemperature(deviceAddress); | ||
+ | Serial.println(); | ||
+ | } | ||
+ | </ | ||
+ | {{tag> |
arduino/silentbase_802_neopixel/programmversion_4.1679165126.txt.gz · Zuletzt geändert: 18.05.2023 12:16 (Externe Bearbeitung)