Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #include <AFMotor.h>
  2. AF_DCMotor infan(1, MOTOR12_1KHZ);
  3. AF_DCMotor exfan(2, MOTOR12_1KHZ);
  4. AF_DCMotor light(3, MOTOR12_1KHZ);
  5. double cur_time = 0;
  6. double time_correct = 0;
  7. double sunrise_time;
  8. double sunset_time;
  9. boolean infanState = false;
  10. boolean exfanState = false;
  11. boolean lightState = false;
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15. Serial.println("No parameters set! Press '?' for a list of commands");
  16. infan.setSpeed(255);
  17. exfan.setSpeed(255);
  18. light.setSpeed(255);
  19. }
  20. void loop() {
  21. if(Serial.available()) {
  22. char in = Serial.read();
  23. if(in == '?') {
  24. printCommands();
  25. }
  26. else if(in == 'F' || in == 'f') {
  27. fanMenu();
  28. }
  29. else if (in == 'L' || in == 'l') {
  30. lightMenu();
  31. }
  32. else if (in == 'S' || in == 's') {
  33. setupMenu();
  34. }
  35. else {
  36. Serial.println("Unknown command. Press '?' for a list of commands");
  37. }
  38. }
  39. if(infanState) {
  40. infan.run(FORWARD);
  41. }
  42. else {
  43. infan.run(RELEASE);
  44. }
  45. if(exfanState) {
  46. exfan.run(FORWARD);
  47. }
  48. else {
  49. exfan.run(RELEASE);
  50. }
  51. if(lightState && sunrise_time != 0 && sunset_time != 0) {
  52. light.run(FORWARD);
  53. }
  54. else {
  55. light.run(RELEASE);
  56. }
  57. cur_time = millis() * 3600000;
  58. }
  59. void fanMenu() {
  60. Serial.println("Fan menu");
  61. Serial.print("Intake fan state: ");
  62. boolToOnOff(infanState);
  63. Serial.print("Exhaust fan state: ");
  64. boolToOnOff(exfanState);
  65. Serial.println("Press '1' to change state of intake fan");
  66. Serial.println("Press '2' to change state of exhaust fan");
  67. Serial.println("Press '0' to exit menu");
  68. int waittime1 = 0;
  69. while (true) {
  70. if(Serial.available()) {
  71. char serIn = Serial.read();
  72. if(serIn == '1') {
  73. infanChange();
  74. goto bailout;
  75. }
  76. else if(serIn == '2') {
  77. exfanChange();
  78. goto bailout;
  79. }
  80. else if(serIn == '0') {
  81. goto bailout;
  82. }
  83. else {
  84. Serial.println("Unknown input!");
  85. }
  86. }
  87. }
  88. bailout:;
  89. Serial.println("Back to main menu");
  90. }
  91. void lightMenu() {
  92. Serial.println("Light menu");
  93. if(sunrise_time == 0 || sunset_time == 0) {
  94. Serial.println("Light settings not configured! Light cannot be enabled");
  95. }
  96. else {
  97. Serial.print("Sunrise time: ");
  98. Serial.println(sunrise_time);
  99. Serial.print("Sunset time: ");
  100. Serial.println(sunset_time);
  101. }
  102. Serial.print("Current time: ");
  103. Serial.println(cur_time);
  104. Serial.println("Press 1 to configure sunrise time");
  105. Serial.println("Press 2 to configure sunset time");
  106. Serial.println("Press 3 to establish current time");
  107. Serial.println("Press 0 to return to main menu");
  108. while(true) {
  109. if(Serial.available()) {
  110. char serIn = Serial.read();
  111. if(serIn == '1') {
  112. configureSunrise();
  113. }
  114. else if(serIn == '2') {
  115. configureSunset();
  116. }
  117. else if (serIn == '3') {
  118. configureTime();
  119. }
  120. else if (serIn == '0') {
  121. goto breakout2;
  122. }
  123. else {
  124. Serial.println("Unknown command");
  125. }
  126. }
  127. }
  128. breakout2:;
  129. Serial.println("Returning to main menu");
  130. }
  131. void configureSunrise() {
  132. Serial.println("Please enter time for 'sunrise': ");
  133. Serial.println("Use format HH");
  134. while(!Serial.available()) {}
  135. double tempRise = 0;
  136. int serIn = Serial.read();
  137. if(serIn <= 48 && serIn >= 57) {
  138. tempRise = serIn * 10;
  139. }
  140. else {
  141. Serial.println("Unknown entry!");
  142. }
  143. serIn = Serial.read();
  144. if(serIn <= 48 && serIn >= 57) {
  145. sunrise_time = tempRise + serIn;
  146. }
  147. }
  148. void configureSunset() {
  149. }
  150. void configureTime() {
  151. }
  152. void setupMenu() {
  153. }
  154. void boolToOnOff(boolean in) {
  155. if(in) {
  156. Serial.println("On");
  157. }
  158. else {
  159. Serial.println("Off");
  160. }
  161. }
  162. void infanChange() {
  163. if(infanState) {
  164. infanState = false;
  165. Serial.println("Intake fan disabled");
  166. }
  167. else {
  168. infanState = true;
  169. Serial.println("Intake fan enabled");
  170. }
  171. }
  172. void exfanChange() {
  173. if(exfanState) {
  174. exfanState = false;
  175. Serial.println("Exhaust fan disabled");
  176. }
  177. else {
  178. exfanState = true;
  179. Serial.println("Exhaust fan enabled");
  180. }
  181. }
  182. void printCommands() {
  183. Serial.println("List of commands:");
  184. Serial.println("F: Go to fan menu");
  185. Serial.println("L: Go to lighting menu");
  186. Serial.println("S: Enter setup");
  187.  
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement