Advertisement
Guest User

Untitled

a guest
May 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. /*
  2. *
  3. * LINEAR ACTUATOR & FLIPPER PROGRAM CONTROL!
  4.  
  5.  
  6. further modified 19 May 2016, Thayer ENGS21 proj, Wes Kendrick.
  7. Using grove shield,
  8.  
  9.  
  10. modified even more for the linear actuator 5/25/2016
  11.  
  12. CONFIG!!!
  13. servo wired to D7
  14. switch to D5
  15.  
  16. //potentiometer is wired into A0. Note that the cable, as it is currently configured, is screwed up, need jumper cables
  17. //brown == ground; red = power, orange == signal.
  18.  
  19.  
  20. */
  21.  
  22. #include <Servo.h>
  23. Servo myservo; // create servo object to control a servo
  24.  
  25. //CONSTANTS FOR EZ CONFIGURATION!!!
  26.  
  27. const int DI_button_pin=8;
  28. const int servo = 7;
  29.  
  30. //put the linear actuator motor control cable in the grove slot labled D2. Don't switch up the orientation
  31. const int purple = 2;
  32. const int grey = 3;
  33.  
  34.  
  35.  
  36. bool go;
  37. bool reached;
  38. int flipperTriggered;
  39.  
  40. int counter;
  41.  
  42. void setup() {
  43. myservo.attach(7); // attaches the servo on pin 7 to the servo object
  44.  
  45. pinMode(DI_button_pin,INPUT);
  46. digitalWrite(DI_button_pin,HIGH); ///////that super strange line that fixes stuff
  47.  
  48. pinMode(purple,OUTPUT);
  49. pinMode(grey,OUTPUT);
  50. Serial.begin(9600);
  51. myservo.write(160);
  52. digitalWrite(purple,LOW);
  53. digitalWrite(grey,LOW);
  54. go = false;
  55. reached = false;
  56. counter = 0;
  57. flipperTriggered = 0;;
  58. }
  59.  
  60. void loop() {
  61.  
  62. int buttonValue=digitalRead(DI_button_pin);
  63. //Serial.println(buttonValue);
  64.  
  65.  
  66. if(buttonValue==LOW){
  67. go = true;
  68. reached = false;
  69. flipperTriggered = 0;
  70.  
  71. }
  72.  
  73. int potentiometerValue = analogRead(A0);
  74.  
  75. if(go){
  76.  
  77. counter++;
  78.  
  79. if(counter > 500 && reached == false){
  80. reached = true;
  81. flipperTriggered = 1;
  82. }
  83.  
  84. if(potentiometerValue <= 1020 && reached == false){
  85. digitalWrite(purple,HIGH);
  86. }
  87. if(potentiometerValue >= 1000){
  88. reached = true;
  89. flipperTriggered = 1;
  90. }
  91. if(reached && potentiometerValue >= 100){
  92. digitalWrite(purple,HIGH);
  93. digitalWrite(grey,HIGH);
  94. }
  95. if(potentiometerValue <=200 && reached == true){
  96. go = false;
  97. digitalWrite(purple,LOW);
  98. digitalWrite(grey,LOW);
  99. counter = 0;
  100.  
  101. }
  102. }
  103.  
  104. Serial.println(myservo.read());
  105.  
  106. // flipper control!
  107.  
  108. if(flipperTriggered == 1){
  109. myservo.write(0);
  110. if(myservo.read() < 5){
  111. flipperTriggered = 2;
  112. }
  113. }
  114.  
  115. if(flipperTriggered == 2){
  116. myservo.write(160);
  117. }
  118.  
  119. delay(1);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement