Arduino Stand Timer


Arduino Uno
4 Digit LED Display
10K Potentiometer
Momentary Button
Vibration Motor
Photoresistor
2N2222 Transistor
1K Resistor
4.7K Resistor
(2) Neopixels



  1. // arduino stand timer ii
  2. // pkvi
  3. #include <TM1637Display.h>
  4. #define CLK 9
  5. #define DIO 10
  6. TM1637Display display = TM1637Display(CLK, DIO);
  7. #include "FastLED.h"
  8. #define NUM_LEDS 2
  9. #define LED_TYPE WS2812B
  10. #define COLOR_ORDER GRB
  11. CRGB leds[NUM_LEDS];
  12. const int NEO = 3;
  13. int num;
  14. int num_pre;
  15. int num_set;
  16. int num_dis;
  17. int num_out;
  18. int num_sto;
  19. int col;
  20. const int time_pot = A5;
  21. const int button = 6;
  22. const int vibrate = 11;
  23. const int photo = A3;
  24. int state;
  25. int up;
  26. int more;
  27. int p;
  28. void setup() {
  29. Serial.begin(9600);
  30. display.clear();
  31. display.setBrightness(2);
  32. FastLED.addLeds<LED_TYPE, NEO, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  33. pixel(0, 0, 255);
  34. pinMode(button, INPUT_PULLUP);
  35. pinMode(vibrate, OUTPUT);
  36. digitalWrite(vibrate, LOW);
  37. }
  38. void loop() {
  39. if (state == 0) {
  40. // select minutes 1-60
  41. // wait for button
  42. while (digitalRead(button) == HIGH) {
  43. num = analogRead(time_pot);
  44. num_pre = map(num, 1023, 0, 1, 30);
  45. num_set = round(num_pre);
  46. num_set = num_set * 100;
  47. display.showNumberDecEx(num_set, 0b01000000, false, 4, 0);
  48. }
  49. num_sto = num_pre;
  50. state = 1;
  51. pixel(0, 0, 0);
  52. } else if (state == 1) {
  53. // minute count down
  54. for (num_out = num_pre; num_out > 1; num_out--) {
  55. num_dis = num_out * 100;
  56. display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
  57. delay(60000);
  58. }
  59. state = 2;
  60. } else if (state == 2) {
  61. // 60 second count down
  62. for (num_dis = 60; num_dis > 0; num_dis--) {
  63. display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
  64. delay(1000);
  65. }
  66. state = 3;
  67. } else if (state == 3) {
  68. // warning
  69. pixel(255, 0, 0);
  70. display.clear();
  71. alert();
  72. // standing limit
  73. pixel(0, 0, 255);
  74. display.showNumberDecEx(100, 0b01000000, false, 4, 0);
  75. delay(1000);
  76. for (num_dis = 59; num_dis > 0; num_dis--) {
  77. display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
  78. delay(500);
  79. photo_read();
  80. if (more == 0) {
  81. while (more == 0) {
  82. // no cheating
  83. alert();
  84. }
  85. }
  86. }
  87. // wait for reset
  88. photo_read();
  89. pixel(0, 255, 0);
  90. num_pre = num_sto;
  91. num_dis = num_pre * 100;
  92. display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
  93. while (more > 0) {
  94. photo_read();
  95. }
  96. state = 1;
  97. pixel(0, 0, 0);
  98. } else {
  99. // ayh
  100. }
  101. }
  102. void alert() {
  103. photo_read();
  104. while (more == 0) {
  105. digitalWrite(vibrate, HIGH);
  106. delay(1000);
  107. digitalWrite(vibrate, LOW);
  108. delay(500);
  109. photo_read();
  110. }
  111. }
  112. void photo_read() {
  113. up = 0;
  114. more = 0;
  115. for (p = 0; p < 20; p++) {
  116. up = analogRead(photo);
  117. more = more + up;
  118. delay(25);
  119. }
  120. }
  121. void pixel(int r, int g, int b) {
  122. for (int w = 0; w < NUM_LEDS; w++) {
  123. leds[w] = CRGB (r, g, b);
  124. FastLED.show();
  125. }
  126. }

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.00476