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."
319 miters
122 tenons
Subscribe
0.0011
Arduino Flush-Less


  1. // Arduino Flush-Less (1.0)
  2. // pkvi
  3. // CapacitiveSensor Library _ Paul Badger
  4. // PFOD _ Dr. Matthew Ford
  5. #include "CapacitiveSensor.h"
  6. #include "Servo.h"
  7. #include "pfodParser.h"
  8. #include "Stream.h"
  9. pfodParser parser;
  10. // Pin 6 (10M) and 5 (1K)
  11. CapacitiveSensor deucetouch = CapacitiveSensor(6,5);
  12. // Pin 7 (10M) and 8 (1K)
  13. CapacitiveSensor flushtouch = CapacitiveSensor(8,7);
  14. Servo tankservo;
  15. Servo flushservo;
  16. int tankOFF = 120; // Tank Servo Position OFF
  17. int tankON = 0; // Tank Servo Position ON
  18. int flushOFF = 180; // Flush Servo Position OFF
  19. int flushON = 0; // Flush Servo Position ON
  20. int bowlvalve = 10; // Bowl Pin 10
  21. int pooLED = 9; // LED Pin 9
  22. void setup()
  23. {
  24. Serial.begin(9600);
  25. for (int i=5; i>0; i--) { // Wait
  26. Serial.print(i);
  27. delay(1000);
  28. }
  29. parserSetup();
  30. Serial.println();
  31. Serial1.begin(9600); // Serial1 BlueTooth (Micro)
  32. pinMode(bowlvalve, OUTPUT);
  33. pinMode(pooLED, OUTPUT);
  34. tankservo.attach(3); // Tank Pin 3
  35. flushservo.attach(4); // Flush Pin 4
  36. digitalWrite(pooLED, HIGH); // Setup Alert
  37. delay(1000);
  38. digitalWrite(pooLED, LOW);
  39. delay(1000);
  40. digitalWrite(pooLED, HIGH);
  41. delay(1000);
  42. }
  43. void loop()
  44. {
  45. // Turn OFF All
  46. flushservo.write(flushOFF); // Flush CLOSED
  47. tankservo.write(tankOFF); // Tank CLOSED
  48. digitalWrite(bowlvalve, LOW); // Bowl CLOSED
  49. digitalWrite(pooLED, LOW); // LED OFF
  50. // Read Sensors
  51. long tank_touch = deucetouch.capacitiveSensor(30);
  52. long flush_touch = flushtouch.capacitiveSensor(30);
  53. // Deuce, Flush or Stand By
  54. if (tank_touch > 1500 && flush_touch < 500){ numbertwo(); }
  55. else if (flush_touch > 1500 && tank_touch < 500){ emptybowl(); }
  56. else ( delay(10) );
  57. // Print Sensors (Testing)
  58. Serial.print(tank_touch);
  59. Serial.print("\t");
  60. Serial.println(flush_touch);
  61. // Write Bluetooth Menu
  62. if (Serial1.available()) {
  63. byte in = Serial1.read();
  64. byte cmd = parser.parse(in);
  65. if (cmd != 0) {
  66. if ('.' == cmd) {
  67. Serial1.print(F("{."));
  68. Serial1.print(F("<gy>HackADay Prize"));
  69. Serial1.print(F("|A~<bg o><+8>Deuce"));
  70. Serial1.print(F("|B~<bg n><+8>Flush"));
  71. Serial1.print(F("}"));
  72. // Handle Bluetooth Buttons
  73. } else if('A'==cmd) { // Deuce
  74. numbertwo();
  75. Serial1.print(F("{}")); // Update
  76. } else if('B'==cmd) { // Flush
  77. emptybowl();
  78. Serial1.print(F("{}")); // Update
  79. } else {
  80. Serial1.print(F("{}"));
  81. }
  82. }
  83. }
  84. }
  85. // Deuce
  86. void numbertwo() {
  87. digitalWrite(pooLED, HIGH); // LED ON
  88. digitalWrite(bowlvalve, HIGH); // Bowl OPEN
  89. tankservo.write(tankON); // Tank OPEN
  90. delay(13000); /* Adjust Per Model */
  91. return;
  92. //Code To Lock Out NumberTwo()?
  93. }
  94. // Flush
  95. void emptybowl() {
  96. digitalWrite(pooLED, HIGH); // LED ON
  97. flushservo.write(flushON); // Flush OPEN
  98. digitalWrite(bowlvalve, HIGH); // Bowl OPEN
  99. tankservo.write(tankON); // Tank OPEN
  100. delay(6000);
  101. flushservo.write(flushOFF); // Flush CLOSED
  102. delay(2000);
  103. digitalWrite(bowlvalve, LOW); // Bowl CLOSED
  104. delay(15000); /* Adjust Per Model */
  105. return;
  106. }
  107. // BlueTooth Tasks
  108. byte cmdByte;
  109. byte parserByteCounter;
  110. byte parserState;
  111. static const byte pfodMaxMsgLen = 0xff;
  112. static const byte pfodStartMsg = (byte)'{';
  113. static const byte pfodEndMsg = (byte)'}';
  114. static const byte pfodWaitingForStart = 0xff;
  115. static const byte pfodInMsg = 0;
  116. void parserSetup() {
  117. parserByteCounter = 0;
  118. cmdByte = 0;
  119. parserState = pfodWaitingForStart;
  120. }
  121. byte parse(byte in) {
  122. parserByteCounter++;
  123. if (parserState == pfodWaitingForStart) {
  124. if (in == pfodStartMsg) {
  125. parserSetup();
  126. parserState = pfodInMsg;
  127. }
  128. parserByteCounter = 1;
  129. return 0;
  130. }
  131. if ((parserByteCounter == pfodMaxMsgLen) &&
  132. (in != pfodEndMsg)) {
  133. parserSetup();
  134. return 0;
  135. }
  136. if (in == pfodEndMsg) {
  137. byte pfodMsgCmd = cmdByte;
  138. parserSetup();
  139. return pfodMsgCmd;
  140. } else if (cmdByte == 0) {
  141. cmdByte = in;
  142. }
  143. return 0;
  144. }