PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <FastLED.h>
  2. #define LED_PIN 5
  3. #define COLOR_ORDER GRB
  4. #define CHIPSET WS2811
  5. #define NUM_LEDS 30
  6. #define BRIGHTNESS 200
  7. #define FRAMES_PER_SECOND 60
  8. bool gReverseDirection = false;
  9. CRGB leds[NUM_LEDS];
  10. void setup() {
  11. delay(3000); // sanity delay
  12. FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  13. FastLED.setBrightness( BRIGHTNESS );
  14. }
  15. void loop()
  16. {
  17. // Add entropy to random number generator; we use a lot of it.
  18. // random16_add_entropy( random());
  19. Fire2012(); // run simulation frame
  20. FastLED.show(); // display this frame
  21. FastLED.delay(1000 / FRAMES_PER_SECOND);
  22. }
  23. // Fire2012 by Mark Kriegsman, July 2012
  24. // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
  25. ////
  26. // This basic one-dimensional 'fire' simulation works roughly as follows:
  27. // There's a underlying array of 'heat' cells, that model the temperature
  28. // at each point along the line. Every cycle through the simulation,
  29. // four steps are performed:
  30. // 1) All cells cool down a little bit, losing heat to the air
  31. // 2) The heat from each cell drifts 'up' and diffuses a little
  32. // 3) Sometimes randomly new 'sparks' of heat are added at the bottom
  33. // 4) The heat from each cell is rendered as a color into the leds array
  34. // The heat-to-color mapping uses a black-body radiation approximation.
  35. //
  36. // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
  37. //
  38. // This simulation scales it self a bit depending on NUM_LEDS; it should look
  39. // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
  40. //
  41. // I recommend running this simulation at anywhere from 30-100 frames per second,
  42. // meaning an interframe delay of about 10-35 milliseconds.
  43. //
  44. // Looks best on a high-density LED setup (60+ pixels/meter).
  45. //
  46. //
  47. // There are two main parameters you can play with to control the look and
  48. // feel of your fire: COOLING (used in step 1 above), and SPARKING (used
  49. // in step 3 above).
  50. //
  51. // COOLING: How much does the air cool as it rises?
  52. // Less cooling = taller flames. More cooling = shorter flames.
  53. // Default 50, suggested range 20-100
  54. #define COOLING 55
  55. // SPARKING: What chance (out of 255) is there that a new spark will be lit?
  56. // Higher chance = more roaring fire. Lower chance = more flickery fire.
  57. // Default 120, suggested range 50-200.
  58. #define SPARKING 120
  59. void Fire2012()
  60. {
  61. // Array of temperature readings at each simulation cell
  62. static byte heat[NUM_LEDS];
  63. // Step 1. Cool down every cell a little
  64. for( int i = 0; i < NUM_LEDS; i++) {
  65. heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  66. }
  67. // Step 2. Heat from each cell drifts 'up' and diffuses a little
  68. for( int k= NUM_LEDS - 1; k >= 2; k--) {
  69. heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  70. }
  71. // Step 3. Randomly ignite new 'sparks' of heat near the bottom
  72. if( random8() < SPARKING ) {
  73. int y = random8(7);
  74. heat[y] = qadd8( heat[y], random8(160,255) );
  75. }
  76. // Step 4. Map from heat cells to LED colors
  77. for( int j = 0; j < NUM_LEDS; j++) {
  78. CRGB color = HeatColor( heat[j]);
  79. int pixelnumber;
  80. if( gReverseDirection ) {
  81. pixelnumber = (NUM_LEDS-1) - j;
  82. } else {
  83. pixelnumber = j;
  84. }
  85. leds[pixelnumber] = color;
  86. }
  87. }