Drone Hat

1. power up --> 4.5V bridge with 2N2222 transistor
2. up (connect) --> 3.3V bridge w/ 2N2222
3. down (connect) --> mechanical relay (5V) to gnd toggle
4. lower button (level) --> 3.3V bridge w/ 2N2222
5. upper button (launch) --> 3.3V bridge w/ 2N2222
6. upper button (land)



  1. // pkvi
  2. #include <Servo.h>
  3. #include "FastLED.h"
  4. Servo doors;
  5. int closed = 5;
  6. int openned = 40;
  7. #define NUM_LEDS 60
  8. CRGB leds[NUM_LEDS];
  9. #define PIN 4
  10. const int up = 3; // relay
  11. const int launch = 6;
  12. const int button = 7;
  13. const int level = 8;
  14. const int down = 10;
  15. const int power = 12;
  16. int buttonstate;
  17. int flystate = 0;
  18. void setup() {
  19. FastLED.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  20. doors.attach(11);
  21. doors.write(closed);
  22. pinMode(up, OUTPUT);
  23. pinMode(launch, OUTPUT);
  24. pinMode(button, INPUT);
  25. pinMode(level, OUTPUT);
  26. pinMode(down, OUTPUT);
  27. pinMode(power, OUTPUT);
  28. digitalWrite(up, LOW);
  29. digitalWrite(launch, LOW);
  30. digitalWrite(level, LOW);
  31. digitalWrite(down, LOW);
  32. digitalWrite(power, LOW);
  33. delay(500);
  34. }
  35. void loop() {
  36. buttonstate = digitalRead(button);
  37. if (buttonstate == HIGH) {
  38. if (flystate == 0) {
  39. launchit();
  40. } else if (flystate == 1) {
  41. land();
  42. } else {
  43. // error
  44. }
  45. } else {
  46. Sparkle(0x00, 0x00, 0xff, 0);
  47. }
  48. }
  49. void launchit() {
  50. doors.write(openned);
  51. delay(1000);
  52. doors.write(closed);
  53. digitalWrite(power, HIGH);
  54. delay(300);
  55. digitalWrite(power, LOW);
  56. delay(300);
  57. digitalWrite(up, HIGH);
  58. delay(750);
  59. digitalWrite(up, LOW);
  60. delay(300);
  61. digitalWrite(down, HIGH);
  62. delay(300);
  63. digitalWrite(down, LOW);
  64. delay(300);
  65. digitalWrite(launch, HIGH);
  66. delay(300);
  67. digitalWrite(launch, LOW);
  68. flystate = 1;
  69. }
  70. void land () {
  71. digitalWrite(launch, HIGH);
  72. delay(300);
  73. digitalWrite(launch, LOW);
  74. delay(300);
  75. digitalWrite(power, HIGH);
  76. delay(1500);
  77. digitalWrite(power, LOW);
  78. flystate = 0;
  79. }
  80. void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  81. int Pixel = random(NUM_LEDS);
  82. setPixel(Pixel, red, green, blue);
  83. showStrip();
  84. delay(SpeedDelay);
  85. setPixel(Pixel, 0, 0, 0);
  86. }
  87. void showStrip() {
  88. #ifdef ADAFRUIT_NEOPIXEL_H
  89. // NeoPixel
  90. strip.show();
  91. #endif
  92. #ifndef ADAFRUIT_NEOPIXEL_H
  93. // FastLED
  94. FastLED.show();
  95. #endif
  96. }
  97. void setPixel(int Pixel, byte red, byte green, byte blue) {
  98. #ifdef ADAFRUIT_NEOPIXEL_H
  99. // NeoPixel
  100. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  101. #endif
  102. #ifndef ADAFRUIT_NEOPIXEL_H
  103. // FastLED
  104. leds[Pixel].r = red;
  105. leds[Pixel].g = green;
  106. leds[Pixel].b = blue;
  107. #endif
  108. }
  109. void setAll(byte red, byte green, byte blue) {
  110. for (int i = 0; i < NUM_LEDS; i++ ) {
  111. setPixel(i, red, green, blue);
  112. }
  113. showStrip();
  114. }

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