Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
buymeacoffee.com/pkvi
scored.co/u/pkvi_halfkdeltaxsq
Miter
Why Ayh?
Miter
@pkvi
"...may not meet professional standards."
371 miters
122 tenons
Subscribe
0.0017
Arduino Darkest Timeline Bot


1. Arduino Uno
2. HC-06 Bluetooth Module
3. SR06 Ultrasonic Sensor
4. 360 Degree Servo
5. Boring Regular Servo
6. Adafruit Neopixel Strip
7. 1000nf Cap
8. 47K Res
9. Cardboard


  1. // Darkest Timeline Bot
  2. // pkvi
  3. // #SixSeasonsAndAMovie
  4. #include <Servo.h>
  5. #include <Adafruit_NeoPixel.h>
  6. // Neopixel
  7. #define PINPIXEL 6
  8. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(3, PINPIXEL,
  9. NEO_GRB + NEO_KHZ800);
  10. // Sensor Values
  11. Servo headservo;
  12. Servo rollservo;
  13. #define trigPin 9
  14. #define echoPin 8
  15. // Set Distance (cm)
  16. int setdist = 40;
  17. // Head Positions
  18. int pos = 3;
  19. int good = 3;
  20. int evil = 158;
  21. // Roll Positions
  22. int forw = 75;
  23. int halt = 90;
  24. int back = 105;
  25. int slow = 80;
  26. // Bleu Cheese
  27. char incom = 0;
  28. void setup() {
  29. Serial.begin (9600);
  30. // Servo Pins
  31. headservo.attach(5);
  32. rollservo.attach(7);
  33. // Set Start Position
  34. headservo.write(good);
  35. rollservo.write(halt);
  36. // Sensor Pins
  37. pinMode(trigPin, OUTPUT);
  38. pinMode(echoPin, INPUT);
  39. // Load Neopixel
  40. pixels.begin();
  41. }
  42. void loop() {
  43. // Happy Blue
  44. pixels.setPixelColor(0, pixels.Color(0, 0, 255));
  45. pixels.setPixelColor(1, pixels.Color(0, 0, 255));
  46. pixels.setPixelColor(2, pixels.Color(0, 0, 255));
  47. pixels.show();
  48. // Roll Bluetooth (Jacob)
  49. if (Serial.available() > 0) {
  50. incom = Serial.read();
  51. if (incom == '1') {
  52. cruel();
  53. }
  54. else if (incom == '2') {
  55. cool();
  56. }
  57. else if (incom == '3') {
  58. gloat();
  59. }
  60. }
  61. // Sensor Sequence
  62. long duration, distance;
  63. digitalWrite(trigPin, LOW);
  64. delayMicroseconds(2);
  65. digitalWrite(trigPin, HIGH);
  66. delayMicroseconds(10);
  67. digitalWrite(trigPin, LOW);
  68. duration = pulseIn(echoPin, HIGH);
  69. // Centimeter Conversion
  70. distance = (duration / 2) / 29.1;
  71. // Print for Testing
  72. Serial.print(distance); Serial.println(" cm");
  73. if (distance > setdist) {
  74. forward();
  75. } else if (distance < setdist) {
  76. backward();
  77. } else {
  78. }
  79. delay(10);
  80. }
  81. void forward() {
  82. rollservo.write(forw);
  83. delay(1000);
  84. rollservo.write(halt);
  85. }
  86. void backward() {
  87. rollservo.write(back);
  88. delay(1000);
  89. rollservo.write(halt);
  90. }
  91. void cruel() {
  92. // Black
  93. pixels.setPixelColor(0, pixels.Color(0, 0, 0));
  94. pixels.setPixelColor(1, pixels.Color(0, 0, 0));
  95. pixels.setPixelColor(2, pixels.Color(0, 0, 0));
  96. pixels.show();
  97. // Become Evil
  98. for (pos = good; pos <= evil; pos += 1) {
  99. headservo.write(pos);
  100. delay(20);
  101. }
  102. delay(500);
  103. // Evil Red
  104. pixels.setPixelColor(0, pixels.Color(255, 0, 0));
  105. pixels.setPixelColor(1, pixels.Color(255, 0, 0));
  106. pixels.setPixelColor(2, pixels.Color(255, 0, 0));
  107. pixels.show();
  108. delay(1000);
  109. rollservo.write(slow);
  110. delay(5000);
  111. // Murder
  112. rollservo.write(halt);
  113. cool();
  114. incom = 0;
  115. }
  116. void cool() {
  117. // Black
  118. pixels.setPixelColor(0, pixels.Color(0, 0, 0));
  119. pixels.setPixelColor(1, pixels.Color(0, 0, 0));
  120. pixels.setPixelColor(2, pixels.Color(0, 0, 0));
  121. pixels.show();
  122. // Become Good
  123. for (pos = evil; pos >= good; pos -= 1) {
  124. headservo.write(pos);
  125. delay(20);
  126. }
  127. incom = 0;
  128. }
  129. void gloat() {
  130. rollservo.write(slow);
  131. delay(5000);
  132. rollservo.write(halt);
  133. }