Advertisement
Guest User

peelerarduino

a guest
Dec 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.57 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo;
  4. Servo peelerservo;
  5. Servo YourServo;
  6. /////////////////// peel btn
  7. const int PeelButton = 7;
  8.  
  9. int PeelButtonpress = 0;
  10.  
  11. boolean PeelButtonStatus = true;
  12. //////////////////
  13.  
  14. const int SwitchButton = 2;
  15.  
  16. int Buttonpress = 0;
  17.  
  18. boolean ButtonStatus = true;
  19.  
  20. int pos = 0;
  21.  
  22. int ledblue = 3;
  23. int ledred=22;
  24. int ledgreen=23;
  25.  
  26. int incomingByte = 0;
  27.  
  28. int tx = 1;
  29.  
  30. int rx = 0;
  31.  
  32. void setup() {
  33.  
  34.  
  35.  
  36. pinMode(ledblue, OUTPUT);
  37.  
  38. pinMode(tx, OUTPUT);
  39.  
  40. pinMode(rx, INPUT);
  41.  
  42. pinMode(SwitchButton, INPUT);
  43.  
  44. // digitalWrite(2, HIGH);
  45. Serial.begin(9600);
  46. }
  47.  
  48.  
  49.  
  50. void loop() {
  51.  
  52. //////
  53.  
  54. PeelButtonpress = digitalRead(PeelButton);
  55.  
  56. if (PeelButtonpress == HIGH){
  57. Serial.println("peel pressed!");
  58. peelerservo.attach(50);
  59.  
  60. peelerservo.write(360);
  61. delay(1000);
  62.  
  63.  
  64.  
  65. }
  66. else
  67. {
  68. peelerservo.detach();
  69. }
  70. ///////////////
  71.  
  72. Buttonpress = digitalRead(SwitchButton);
  73.  
  74. if (Buttonpress == HIGH)
  75.  
  76. if (ButtonStatus == true)
  77.  
  78. {
  79.  
  80. delay(50);
  81.  
  82. myservo.attach(9);
  83.  
  84. Serial.println("Pressed!");
  85.  
  86. digitalWrite(ledblue, HIGH);
  87.  
  88. for (int i = 1; i <= 10; i++) {
  89.  
  90. myservo.write(360);
  91.  
  92. delay(1000);
  93.  
  94. Serial.println(i);
  95.  
  96. }
  97.  
  98. myservo.detach();
  99.  
  100. ButtonStatus = false;
  101.  
  102. digitalWrite(ledblue, LOW);
  103.  
  104. delay(50);
  105.  
  106. digitalWrite(ledblue, HIGH);
  107.  
  108. delay(50);
  109.  
  110. digitalWrite(ledblue, LOW);
  111.  
  112. delay(50);
  113.  
  114. digitalWrite(ledblue, HIGH);
  115.  
  116. delay(50);
  117.  
  118. digitalWrite(ledblue, LOW);
  119.  
  120. delay(50);
  121.  
  122. digitalWrite(ledblue, HIGH);
  123.  
  124. delay(50);
  125.  
  126. digitalWrite(ledblue, LOW);
  127.  
  128. delay(500);
  129.  
  130. Serial.println("DONE");
  131.  
  132. }
  133.  
  134. else
  135.  
  136. {
  137.  
  138. delay(50);
  139.  
  140. myservo.attach(9);
  141.  
  142. Serial.println("Pressed! ");
  143.  
  144. for (int i = 1; i <= 10; i++) {
  145.  
  146. myservo.write(0);
  147.  
  148. delay(1000);
  149.  
  150. Serial.println(i);
  151.  
  152. }
  153.  
  154. myservo.detach();
  155.  
  156. ButtonStatus = true;
  157.  
  158. }
  159.  
  160. ////////////////////////////////////////////////////////////////////////////////////
  161.  
  162. if (Serial.available() > 0) {
  163.  
  164. // read the incoming byte:
  165.  
  166. incomingByte = Serial.read();
  167.  
  168. // say what you got:
  169. if (incomingByte == 20) {
  170. Serial.println("Connected");
  171. digitalWrite(ledgreen, HIGH);
  172.  
  173. }
  174.  
  175. if (incomingByte == 55) {
  176.  
  177. {
  178.  
  179. delay(50);
  180.  
  181. myservo.attach(9);
  182.  
  183. Serial.println("Going down!");
  184.  
  185. digitalWrite(ledblue, HIGH);
  186.  
  187. for (int i = 1; i <= 7; i++) {
  188.  
  189. myservo.write(0);
  190.  
  191. delay(1000);
  192.  
  193. Serial.println(i);
  194.  
  195. }
  196.  
  197. myservo.detach();
  198.  
  199. ButtonStatus = true;
  200.  
  201. digitalWrite(ledblue, LOW);
  202.  
  203. delay(50);
  204.  
  205. digitalWrite(ledblue, HIGH);
  206.  
  207. delay(50);
  208.  
  209. digitalWrite(ledblue, LOW);
  210.  
  211. delay(50);
  212.  
  213. digitalWrite(ledblue, HIGH);
  214.  
  215. delay(50);
  216.  
  217. digitalWrite(ledblue, LOW);
  218.  
  219. delay(50);
  220.  
  221. digitalWrite(ledblue, HIGH);
  222.  
  223. delay(50);
  224.  
  225. digitalWrite(ledblue, LOW);
  226.  
  227. delay(500);
  228.  
  229. Serial.println("DONE");
  230.  
  231.  
  232.  
  233.  
  234.  
  235. }
  236.  
  237.  
  238.  
  239. {
  240.  
  241. delay(50);
  242.  
  243. myservo.attach(9);
  244.  
  245. Serial.println("Going up!");
  246.  
  247. digitalWrite(ledblue, HIGH);
  248.  
  249. for (int i = 1; i <= 7; i++) {
  250.  
  251. myservo.write(360);
  252.  
  253. delay(1000);
  254.  
  255. Serial.println(i);
  256.  
  257. }
  258.  
  259. myservo.detach();
  260.  
  261. ButtonStatus = true;
  262.  
  263. digitalWrite(ledblue, LOW);
  264.  
  265. delay(50);
  266.  
  267. digitalWrite(ledblue, HIGH);
  268.  
  269. delay(50);
  270.  
  271. digitalWrite(ledblue, LOW);
  272.  
  273. delay(50);
  274.  
  275. digitalWrite(ledblue, HIGH);
  276.  
  277. delay(50);
  278.  
  279. digitalWrite(ledblue, LOW);
  280.  
  281. delay(50);
  282.  
  283. digitalWrite(ledblue, HIGH);
  284.  
  285. delay(50);
  286.  
  287. digitalWrite(ledblue, LOW);
  288.  
  289. delay(500);
  290.  
  291. Serial.println("DONE");
  292.  
  293.  
  294.  
  295.  
  296.  
  297. }
  298.  
  299. }
  300.  
  301.  
  302.  
  303.  
  304.  
  305. //////////////////////////////////////////////////////////// WASHER SERVO
  306.  
  307. if (incomingByte == 54) {
  308.  
  309. {
  310.  
  311. delay(50);
  312.  
  313. YourServo.attach(11);
  314.  
  315. Serial.println("Washing blades");
  316.  
  317. digitalWrite(ledblue, HIGH);
  318.  
  319. for (int i = 1; i <= 7; i++) {
  320.  
  321. YourServo.write(0);
  322.  
  323. delay(1000);
  324.  
  325. Serial.println(i);
  326.  
  327. }
  328.  
  329. YourServo.detach();
  330.  
  331. ButtonStatus = true;
  332.  
  333. digitalWrite(ledblue, LOW);
  334.  
  335. delay(50);
  336.  
  337. digitalWrite(ledblue, HIGH);
  338.  
  339. delay(50);
  340.  
  341. digitalWrite(ledblue, LOW);
  342.  
  343. delay(50);
  344.  
  345. digitalWrite(ledblue, HIGH);
  346.  
  347. delay(50);
  348.  
  349. digitalWrite(ledblue, LOW);
  350.  
  351. delay(50);
  352.  
  353. digitalWrite(ledblue, HIGH);
  354.  
  355. delay(50);
  356.  
  357. digitalWrite(ledblue, LOW);
  358.  
  359. delay(500);
  360.  
  361. Serial.println("DONE");
  362.  
  363.  
  364.  
  365.  
  366.  
  367. }
  368.  
  369.  
  370.  
  371. {
  372.  
  373. delay(50);
  374.  
  375. YourServo.attach(11);
  376.  
  377. Serial.println("Washer going back!");
  378.  
  379. digitalWrite(ledblue, HIGH);
  380.  
  381. for (int i = 1; i <= 7; i++) {
  382.  
  383. YourServo.write(360);
  384.  
  385. delay(1000);
  386.  
  387. Serial.println(i);
  388.  
  389. }
  390.  
  391. YourServo.detach();
  392.  
  393. ButtonStatus = true;
  394.  
  395. digitalWrite(ledblue, LOW);
  396.  
  397. delay(50);
  398.  
  399. digitalWrite(ledblue, HIGH);
  400.  
  401. delay(50);
  402.  
  403. digitalWrite(ledblue, LOW);
  404.  
  405. delay(50);
  406.  
  407. digitalWrite(ledblue, HIGH);
  408.  
  409. delay(50);
  410.  
  411. digitalWrite(ledblue, LOW);
  412.  
  413. delay(50);
  414.  
  415. digitalWrite(ledblue, HIGH);
  416.  
  417. delay(50);
  418.  
  419. digitalWrite(ledblue, LOW);
  420.  
  421. delay(500);
  422.  
  423. Serial.println("DONE");
  424.  
  425.  
  426.  
  427.  
  428.  
  429. }
  430.  
  431. }
  432.  
  433. }
  434.  
  435.  
  436.  
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement