Code Dump
Single Servo Serial Position
  1. // Serial to Servo Position
  2. #include <Servo.h>
  3. Servo servo;
  4. int pos;
  5. void setup() {
  6. servo.attach(6);
  7. Serial.begin(9600);
  8. servo.write(90);
  9. }
  10. void loop() {
  11. if (Serial.available() > 0) {
  12. pos = Serial.parseInt();
  13. Serial.println(pos);
  14. servo.write(pos);
  15. delay(100);
  16. }
  17. }

Multi-Servo Serial Position (VarSpeedServo)
  1. // Multi Serial to VarSpeedServo
  2. // https://github.com/netlabtoolkit/VarSpeedServo
  3. /*
  4. Type: Servo No. + Position + . + Speed
  5. Keypad Friendly Position and Speed Testing
  6. Example: 290.120 (Servo 2 Position 90 Speed 120)
  7. 10 to 1180 + .0 to .255 Speed for Servo 1
  8. */
  9. #include <VarSpeedServo.h>
  10. // Name Servos
  11. VarSpeedServo one;
  12. VarSpeedServo two;
  13. VarSpeedServo three;
  14. VarSpeedServo four;
  15. VarSpeedServo five;
  16. // Set Values
  17. String input;
  18. String also;
  19. String then;
  20. int also_int;
  21. int then_pos;
  22. int then_int;
  23. // Default Position and Speed
  24. const int start = 90;
  25. const int set_speed = 50;
  26. void setup() {
  27. Serial.begin(9600);
  28. // Assign Pins
  29. one.attach(2);
  30. two.attach(3);
  31. three.attach(4);
  32. four.attach(5);
  33. five.attach(6);
  34. // Default Position and Speed
  35. one.write(start, set_speed, true);
  36. two.write(start, set_speed, true);
  37. three.write(start, set_speed, true);
  38. four.write(start, set_speed, true);
  39. five.write(start, set_speed, true);
  40. }
  41. void loop() {
  42. if (Serial.available() > 0)
  43. {
  44. // Assign Strings
  45. input = Serial.readString();
  46. also = input;
  47. then = also;
  48. // Get Servo Number
  49. input.remove(1);
  50. // Get Position
  51. also.remove(0, 1);
  52. also_int = also.toInt();
  53. // Get Speed
  54. then_pos = then.indexOf('.');
  55. then_pos = then_pos + 1;
  56. then = then.substring(then_pos);
  57. then_int = then.toInt();
  58. // Print Results
  59. Serial.print(input);
  60. Serial.print(" ");
  61. Serial.print(also_int);
  62. Serial.print(" ");
  63. Serial.println(then_int);
  64. // Run Results
  65. if (input == "1") {
  66. one.write(also_int, then_int, true);
  67. } else if (input == "2") {
  68. two.write(also_int, then_int, true);
  69. } else if (input == "3") {
  70. three.write(also_int, then_int, true);
  71. } else if (input == "4") {
  72. four.write(also_int, then_int, true);
  73. } else if (input == "5") {
  74. five.write(also_int, then_int, true);
  75. }
  76. delay(10);
  77. }
  78. }

Fastled Random Order Block Segment
  1. #include "FastLED.h"
  2. #define NUM_LEDS 200
  3. CRGB leds[NUM_LEDS];
  4. #define PIN 9
  5. int v;
  6. int rd;
  7. int gn;
  8. int bl;
  9. int w;
  10. int start;
  11. int fin;
  12. int state;
  13. int last_state;
  14. // int pot_read;
  15. const int pos_num = 16;
  16. int pos_array[pos_num];
  17. void setup() {
  18. FastLED.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  19. }
  20. void loop() {
  21. blocks(0, 0, 255);
  22. blocks(0, 0, 0);
  23. }
  24. void blocks(int rd, int gn, int bl) {
  25. randomizelist();
  26. for (w = 0; w < pos_num; w++) {
  27. start = pos_array[w];
  28. start = start * 15;
  29. fin = start + 15;
  30. for (v = start; v < fin; v++) {
  31. setPixel(v, rd, gn, bl);
  32. }
  33. showStrip();
  34. // escape/change function with pot (optional)
  35. // pot_read = analogRead(A0);
  36. // state = map(pot_read, 0, 1023, 1, 10);
  37. // if (state != last_state) {
  38. // return;
  39. // }
  40. delay(750);
  41. }
  42. }
  43. void randomizelist() {
  44. unsigned char chosen[pos_num];
  45. unsigned char index_pt, log_pt;
  46. for (index_pt = 0; index_pt < pos_num; index_pt++)
  47. chosen[index_pt] = 0;
  48. randomSeed(analogRead(A0));
  49. for (index_pt = 0; index_pt < pos_num; index_pt++) {
  50. int r = random(pos_num - index_pt);
  51. for (log_pt = 0; log_pt <= r; log_pt++) {
  52. r += chosen[log_pt];
  53. }
  54. chosen[r] = 1;
  55. pos_array[index_pt] = r;
  56. }
  57. }
  58. void showStrip() {
  59. #ifdef ADAFRUIT_NEOPIXEL_H
  60. // NeoPixel
  61. strip.show();
  62. #endif
  63. #ifndef ADAFRUIT_NEOPIXEL_H
  64. // FastLED
  65. FastLED.show();
  66. #endif
  67. }
  68. void setPixel(int Pixel, byte red, byte green, byte blue) {
  69. #ifdef ADAFRUIT_NEOPIXEL_H
  70. // NeoPixel
  71. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  72. #endif
  73. #ifndef ADAFRUIT_NEOPIXEL_H
  74. // FastLED
  75. leds[Pixel].r = red;
  76. leds[Pixel].g = green;
  77. leds[Pixel].b = blue;
  78. #endif
  79. }
  80. void setAll(byte red, byte green, byte blue) {
  81. for (int i = 0; i < NUM_LEDS; i++ ) {
  82. setPixel(i, red, green, blue);
  83. }
  84. showStrip();
  85. }

Lightning Code
  1. // Lighting Cloud
  2. // James Bruce
  3. #include <FastLED.h>
  4. #define NUM_LEDS 6
  5. #define DATA_PIN 9
  6. enum Mode {CLOUD, ACID, 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. Serial.begin(9600);
  15. }
  16. void loop() {
  17. constant_lightning();
  18. }
  19. void single_colour(int H) {
  20. for (int i = 0; i < NUM_LEDS; i++) {
  21. leds[i] = CHSV( H, 255, 255);
  22. }
  23. if (lastMode != mode) {
  24. FastLED.show();
  25. lastMode = mode;
  26. }
  27. delay(50);
  28. }
  29. void colour_fade() {
  30. for (int i = 0; i < NUM_LEDS; i++) {
  31. leds[i] = CHSV( fade_h, 255, 255);
  32. }
  33. if (fade_h > 254) {
  34. fade_direction = -1;
  35. }
  36. else if (fade_h < 0) {
  37. fade_direction = 1;
  38. }
  39. fade_h += fade_direction;
  40. FastLED.show();
  41. delay(100);
  42. }
  43. void reset() {
  44. for (int i = 0; i < NUM_LEDS; i++) {
  45. leds[i] = CHSV( 0, 0, 0);
  46. }
  47. FastLED.show();
  48. }
  49. void acid_cloud() {
  50. for (int i = 0; i < NUM_LEDS; i++) {
  51. if (random(0, 100) > 90) {
  52. leds[i] = CHSV( random(0, 255), 255, 255);
  53. }
  54. else {
  55. leds[i] = CHSV(0, 0, 0);
  56. }
  57. }
  58. FastLED.show();
  59. delay(random(5, 100));
  60. reset();
  61. //}
  62. }
  63. void rolling() {
  64. for (int r = 0; r < random(2, 10); r++) {
  65. for (int i = 0; i < NUM_LEDS; i++) {
  66. if (random(0, 100) > 90) {
  67. leds[i] = CHSV( 0, 0, 255);
  68. }
  69. else {
  70. leds[i] = CHSV(0, 0, 0);
  71. }
  72. }
  73. FastLED.show();
  74. delay(random(5, 100));
  75. reset();
  76. }
  77. }
  78. void crack() {
  79. for (int i = 0; i < NUM_LEDS; i++) {
  80. leds[i] = CHSV( 0, 0, 255);
  81. }
  82. FastLED.show();
  83. delay(random(10, 100));
  84. reset();
  85. }
  86. void thunderburst() {
  87. int rs1 = random(0, NUM_LEDS / 2);
  88. int rl1 = random(10, 20);
  89. int rs2 = random(rs1 + rl1, NUM_LEDS);
  90. int rl2 = random(10, 20);
  91. for (int r = 0; r < random(3, 6); r++) {
  92. for (int i = 0; i < rl1; i++) {
  93. leds[i + rs1] = CHSV( 0, 0, 255);
  94. }
  95. if (rs2 + rl2 < NUM_LEDS) {
  96. for (int i = 0; i < rl2; i++) {
  97. leds[i + rs2] = CHSV( 0, 0, 255);
  98. }
  99. }
  100. FastLED.show();
  101. delay(random(10, 50));
  102. reset();
  103. delay(random(10, 50));
  104. }
  105. }
  106. void constant_lightning() {
  107. switch (random(1, 4)) {
  108. case 1:
  109. thunderburst();
  110. delay(random(10, 500));
  111. break;
  112. case 2:
  113. rolling();
  114. break;
  115. case 3:
  116. crack();
  117. delay(random(50, 250));
  118. break;
  119. case 4:
  120. acid_cloud();
  121. break;
  122. }
  123. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,364 miters
123 tenons
Subscribe
0.00364