Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Fire Simulation" - Source Code NOT compiled for: Arduino Nano - Source Code created on: 2024-07-09 15:46:57 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Implement a red fire simulation with WS2812B LEDs */ /* using the FastLED library. Connect the LED data */ /* pin to pin 2. Develop setup and loop functions to */ /* initialize and continuously update the LED states. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
//https://github.com/FastLED/FastLED /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void Fire2012(void); /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t WS2812B_WS2812B_DIN_PIN_D2 = 2; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool WS2812B_WS2812B_DIN_PIN_D2_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float WS2812B_WS2812B_DIN_PIN_D2_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ #define NUM_LEDS 30 #define LED_PIN WS2812B_WS2812B_DIN_PIN_D2 #define COLOR_ORDER GRB #define CHIPSET WS2812B #define BRIGHTNESS 200 #define FRAMES_PER_SECOND 60 #define COOLING 55 #define SPARKING 120 CRGB leds[NUM_LEDS]; void setup(void) { // put your setup code here, to run once: delay(3000); // sanity delay FastLED.addLeds
(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); FastLED.setBrightness(BRIGHTNESS); pinMode(WS2812B_WS2812B_DIN_PIN_D2, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: Fire2012(); // Fire simulation FastLED.show(); FastLED.delay(1000 / FRAMES_PER_SECOND); } void Fire2012() { static uint8_t 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' near the bottom if (random8() < SPARKING) { int y = random8(7); heat[y] = qadd8(heat[y], random8(160, 255)); } // Step 4. Convert heat to LED colors for (int j = 0; j < NUM_LEDS; j++) { leds[j] = HeatColor(heat[j]); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)