Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
scored.co/u/pkvi_mv
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
1767 miters
123 tenons
Subscribe
0.00325
Adafruit Storm in a Box Too



  1. // storm in a box too
  2. // pkvi
  3. #include <FastLED.h>
  4. #define NUM_LEDS 30
  5. #define DATA_PIN 0
  6. enum Mode {CLOUD, OFF, ON, RED, GREEN, BLUE, FADE};
  7. Mode mode = CLOUD;
  8. Mode lastMode = CLOUD;
  9. int fade_h;
  10. int fade_direction = 1;
  11. CRGB leds[NUM_LEDS];
  12. void setup() {
  13. FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  14. for (int w = 0; w < 255; w++) {
  15. glow(0, 0, w);
  16. w = w + 5;
  17. delay(1);
  18. }
  19. for (int w = 255; w > 0; w--) {
  20. glow(0, 0, w);
  21. w = w - 5;
  22. delay(1);
  23. }
  24. }
  25. void loop() {
  26. int pot = analogRead(1);
  27. if (pot > 500) {
  28. constant_lightning();
  29. } else if (pot < 500 && pot > 100) {
  30. for (int w = 0; w < 255; w++) {
  31. glow(0, 0, w);
  32. w = w + 5;
  33. delay(1);
  34. }
  35. for (int w = 255; w > 0; w--) {
  36. glow(0, 0, w);
  37. w = w - 5;
  38. delay(1);
  39. }
  40. } else {
  41. glow(0, 0, 0);
  42. // off
  43. }
  44. }
  45. void constant_lightning() {
  46. switch (random(1, 3)) {
  47. case 1:
  48. thunderburst();
  49. delay(random(10, 500));
  50. break;
  51. case 2:
  52. rolling();
  53. break;
  54. case 3:
  55. crack();
  56. delay(random(50, 250));
  57. break;
  58. }
  59. }
  60. void reset() {
  61. for (int i = 0; i < NUM_LEDS; i++) {
  62. leds[i] = CHSV( 0, 0, 0);
  63. }
  64. FastLED.show();
  65. }
  66. void rolling() {
  67. for (int r = 0; r < random(2, 10); r++) {
  68. for (int i = 0; i < NUM_LEDS; i++) {
  69. if (random(0, 100) > 90) {
  70. leds[i] = CHSV( 0, 0, 255);
  71. }
  72. else {
  73. leds[i] = CHSV(0, 0, 0);
  74. }
  75. }
  76. FastLED.show();
  77. delay(random(5, 100));
  78. reset();
  79. }
  80. }
  81. void crack() {
  82. for (int i = 0; i < NUM_LEDS; i++) {
  83. leds[i] = CHSV( 0, 0, 255);
  84. }
  85. FastLED.show();
  86. delay(random(10, 100));
  87. reset();
  88. }
  89. void thunderburst() {
  90. int rs1 = random(0, NUM_LEDS / 2);
  91. int rl1 = random(10, 20);
  92. int rs2 = random(rs1 + rl1, NUM_LEDS);
  93. int rl2 = random(10, 20);
  94. for (int r = 0; r < random(3, 6); r++) {
  95. for (int i = 0; i < rl1; i++) {
  96. leds[i + rs1] = CHSV( 0, 0, 255);
  97. }
  98. if (rs2 + rl2 < NUM_LEDS) {
  99. for (int i = 0; i < rl2; i++) {
  100. leds[i + rs2] = CHSV( 0, 0, 255);
  101. }
  102. }
  103. FastLED.show();
  104. delay(random(10, 50));
  105. reset();
  106. delay(random(10, 50));
  107. }
  108. }