Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. // breaking down the chicken code to find the bug
  2.  
  3.  
  4. int sensorPin = A0; // select the input pin for the potentiometer
  5. int ledPin = 13; // the number of the LED pin
  6. int ledState = LOW; // ledState used to set the LED
  7. int sensorValue = 0; // variable to store the value coming from the sensor
  8. int homeswPin = 4; // toggle sw for home sequence
  9. int homelimitswPin = 5; // home limit sensor
  10. int timer = 0; // variable to store timer
  11. int uplimitswPin = 2; // up limit switch
  12. int dwnlimitswPin = 3; // down limit switch
  13. int upoutputPin = 7; // output to drive up
  14. int upoutput2Pin = 8; // output to drive up
  15. int dwnoutputPin = 9; // output to drive down
  16. int dwnoutput2Pin = 10; // output to drive down
  17. long previousMillis = 0; // will store last time LED was updated
  18. long interval = timer; // interval at which to change 3519 x sensor value (milliseconds)
  19. long timedown = timedown; // interval at which to change 3519 x sensor value (milliseconds
  20. unsigned long currentMillis = millis();
  21.  
  22. void setup() { // put your setup code here, to run once:
  23.  
  24. pinMode(ledPin, OUTPUT);
  25. pinMode(homeswPin, INPUT_PULLUP);
  26. pinMode(homelimitswPin, INPUT);
  27. pinMode(uplimitswPin, INPUT);
  28. pinMode(dwnlimitswPin, INPUT);
  29. pinMode(upoutputPin, OUTPUT);
  30. pinMode(dwnoutputPin, OUTPUT);
  31. digitalWrite(7, HIGH); // +up safety stop motor
  32. digitalWrite(8, HIGH); // -up safety stop motor
  33. digitalWrite(9, HIGH); // + dwn safety stop motor
  34. digitalWrite(10, HIGH); // - dwn safety stop motor
  35.  
  36. }
  37.  
  38.  
  39. void loop() {
  40.  
  41. { // section 1 find home and stay there
  42. while (digitalRead(homeswPin) == LOW); {
  43. if // dont know where it is but need to find home or up limit
  44. (digitalRead(homeswPin) == LOW && digitalRead(homelimitswPin) == HIGH &&
  45. digitalRead(uplimitswPin) == HIGH && digitalRead(dwnlimitswPin) == HIGH) {
  46. // drives motor up
  47. digitalWrite(upoutputPin, LOW);
  48. }
  49. // move until home or up limit switch found
  50. else if
  51. (digitalRead(homelimitswPin == LOW) || digitalRead(uplimitswPin == LOW)) {
  52. //turn motor off
  53. (digitalWrite(upoutputPin, HIGH));
  54. }
  55. else if
  56. // at up limit need to go home
  57. (digitalRead(homeswPin) == LOW && digitalRead(uplimitswPin) == LOW) {
  58.  
  59. digitalWrite(dwnoutputPin, LOW); // drives motor down
  60. //at home ?
  61. digitalRead(homelimitswPin == HIGH);
  62.  
  63. digitalWrite(dwnoutputPin, HIGH);
  64. } //turns motor off}
  65. else if
  66. // at down limit go home
  67. (digitalRead(homeswPin) == LOW && digitalRead(dwnlimitswPin) == LOW) {
  68. // drives motor up
  69. digitalWrite(upoutputPin, LOW);
  70. //at home
  71. (digitalRead (homelimitswPin) == 0);
  72. //turn motor off
  73. digitalWrite(upoutputPin, HIGH);
  74. }
  75. else
  76. // at home with home switch on stay here
  77. (digitalRead(homeswPin) == LOW && digitalRead(homelimitswPin) == LOW);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement