Arduino Dead or Alive


Arduino Uno
Servo
(2) 10K Potentiometer
LCD Display
Pulse Sensor
(2) 330 ohm Resistor
1000 uf Capacitor
Piezo Buzzer
2N2222 Transistor
4007 Diode
Neopixels
(2) Toggle Switch
MDF


  1. // Arduino Dead or Alive
  2. // pkvi
  3. #include "FastLED.h"
  4. #include "LiquidCrystal.h"
  5. #include "Servo.h"
  6. #define NUM_LEDS 5
  7. CRGB leds[NUM_LEDS];
  8. #define PIN 6
  9. // Beat Var LED
  10. int bpm_led_delay = 500;
  11. // Buzzer Pin
  12. const int ekg = 9;
  13. // LCD
  14. const int rs = 12, en = 11, d4 = 5,
  15. d5 = 4, d6 = 3, d7 = 2;
  16. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  17. // Switch
  18. int aux = 7;
  19. int aux_state = 0;
  20. // Servo
  21. Servo srv;
  22. int st = 110;
  23. int ps = 45;
  24. // Pulse
  25. int pulse = A0
  26. int val;
  27. int tot;
  28. int nxt;
  29. int high;
  30. void setup()
  31. {
  32. Serial.begin(9600);
  33. FastLED.addLeds<WS2812, PIN, GRB>
  34. (leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  35. pinMode(ekg, OUTPUT);
  36. digitalWrite(ekg, LOW);
  37. pinMode(aux, INPUT);
  38. srv.attach(10);
  39. srv.write(st);
  40. lcd.begin(16, 2);
  41. lcd.setCursor(0, 0);
  42. lcd.print("Dead or Alive?");
  43. }
  44. void loop() {
  45. // Motor and Buzzer Switch On/Off
  46. aux_state = digitalRead(aux);
  47. // Reset Value
  48. tot = 0;
  49. nxt = 0;
  50. set_bpm = 0;
  51. // Smoothing Pulse
  52. for (int n = 0; n <= 5; n++) {
  53. for (int i = 0; i <= 25; i++) {
  54. val = analogRead(pulse);
  55. tot = val + tot;
  56. // Display Per Peak
  57. if (val > 580) { // Adjust
  58. // If Motor and Buzzer
  59. if (aux_state == HIGH) {
  60. beat_led(0xff, 0x00, 0x00);
  61. delay(bpm_led_delay);
  62. // If No Motor and Buzzer
  63. } else if (aux_state == LOW) {
  64. beat_led_non(0xff, 0x00, 0x00);
  65. delay(bpm_led_delay);
  66. }
  67. }
  68. delay(2);
  69. }
  70. nxt = tot / 25;
  71. set_bpm = set_bpm + nxt;
  72. }
  73. // BPM Maths
  74. bpm = set_bpm * 12;
  75. // Not Very Accurate .. Meh!
  76. if (bpm > 30) {
  77. lcd.setCursor(0, 0);
  78. lcd.print("Alive!");
  79. lcd.setCursor(0, 1);
  80. lcd.print(bpm);
  81. lcd.print(" BPM");
  82. } else if (bpm <= 30) {
  83. lcd.setCursor(0, 0);
  84. lcd.print("Undead!");
  85. }
  86. }
  87. // Neopixel FastLED Fade Red
  88. // via http://tweaking4all.com
  89. void beat_led(byte red, byte green, byte blue) {
  90. float r, g, b;
  91. for (int k = 0; k < 256; k = k + 8) {
  92. r = (k / 256.0) * red;
  93. g = (k / 256.0) * green;
  94. b = (k / 256.0) * blue;
  95. setAll(r, g, b);
  96. showStrip();
  97. digitalWrite(ekg, HIGH);
  98. srv.write(ps);
  99. }
  100. digitalWrite(ekg, LOW);
  101. srv.write(st);
  102. for (int k = 255; k >= 0; k = k - 10) {
  103. r = (k / 256.0) * red;
  104. g = (k / 256.0) * green;
  105. b = (k / 256.0) * blue;
  106. setAll(r, g, b);
  107. showStrip();
  108. }
  109. }
  110. void beat_led_non(byte red, byte green, byte blue) {
  111. float r, g, b;
  112. for (int k = 0; k < 256; k = k + 8) {
  113. r = (k / 256.0) * red;
  114. g = (k / 256.0) * green;
  115. b = (k / 256.0) * blue;
  116. setAll(r, g, b);
  117. showStrip();
  118. }
  119. for (int k = 255; k >= 0; k = k - 10) {
  120. r = (k / 256.0) * red;
  121. g = (k / 256.0) * green;
  122. b = (k / 256.0) * blue;
  123. setAll(r, g, b);
  124. showStrip();
  125. }
  126. }
  127. void showStrip() {
  128. #ifdef ADAFRUIT_NEOPIXEL_H
  129. strip.show();
  130. #endif
  131. #ifndef ADAFRUIT_NEOPIXEL_H
  132. FastLED.show();
  133. #endif
  134. }
  135. void setPixel(int Pixel, byte red, byte green, byte blue) {
  136. #ifdef ADAFRUIT_NEOPIXEL_H
  137. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  138. #endif
  139. #ifndef ADAFRUIT_NEOPIXEL_H
  140. leds[Pixel].r = red;
  141. leds[Pixel].g = green;
  142. leds[Pixel].b = blue;
  143. #endif
  144. }
  145. void setAll(byte red, byte green, byte blue) {
  146. for (int i = 0; i < NUM_LEDS; i++ ) {
  147. setPixel(i, red, green, blue);
  148. }
  149. showStrip();
  150. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
scored.co/u/pkvi_apostate
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
3,138 miters
123 tenons
Subscribe
0.00398