Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // breaking down the chicken code to find the bug
- int sensorPin = A0; // select the input pin for the potentiometer
- int ledPin = 13; // the number of the LED pin
- int ledState = LOW; // ledState used to set the LED
- int sensorValue = 0; // variable to store the value coming from the sensor
- int homeswPin = 4; // toggle sw for home sequence
- int homelimitswPin = 5; // home limit sensor
- int timer = 0; // variable to store timer
- int uplimitswPin = 2; // up limit switch
- int dwnlimitswPin = 3; // down limit switch
- int upoutputPin = 7; // output to drive up
- int upoutput2Pin = 8; // output to drive up
- int dwnoutputPin = 9; // output to drive down
- int dwnoutput2Pin = 10; // output to drive down
- long previousMillis = 0; // will store last time LED was updated
- long interval = timer; // interval at which to change 3519 x sensor value (milliseconds)
- long timedown = timedown; // interval at which to change 3519 x sensor value (milliseconds
- unsigned long currentMillis = millis();
- void setup() { // put your setup code here, to run once:
- pinMode(ledPin, OUTPUT);
- pinMode(homeswPin, INPUT_PULLUP);
- pinMode(homelimitswPin, INPUT);
- pinMode(uplimitswPin, INPUT);
- pinMode(dwnlimitswPin, INPUT);
- pinMode(upoutputPin, OUTPUT);
- pinMode(dwnoutputPin, OUTPUT);
- digitalWrite(7, HIGH); // +up safety stop motor
- digitalWrite(8, HIGH); // -up safety stop motor
- digitalWrite(9, HIGH); // + dwn safety stop motor
- digitalWrite(10, HIGH); // - dwn safety stop motor
- }
- void loop() {
- { // section 1 find home and stay there
- while (digitalRead(homeswPin) == LOW); {
- if // dont know where it is but need to find home or up limit
- (digitalRead(homeswPin) == LOW && digitalRead(homelimitswPin) == HIGH &&
- digitalRead(uplimitswPin) == HIGH && digitalRead(dwnlimitswPin) == HIGH) {
- // drives motor up
- digitalWrite(upoutputPin, LOW);
- }
- // move until home or up limit switch found
- else if
- (digitalRead(homelimitswPin == LOW) || digitalRead(uplimitswPin == LOW)) {
- //turn motor off
- (digitalWrite(upoutputPin, HIGH));
- }
- else if
- // at up limit need to go home
- (digitalRead(homeswPin) == LOW && digitalRead(uplimitswPin) == LOW) {
- digitalWrite(dwnoutputPin, LOW); // drives motor down
- //at home ?
- digitalRead(homelimitswPin == HIGH);
- digitalWrite(dwnoutputPin, HIGH);
- } //turns motor off}
- else if
- // at down limit go home
- (digitalRead(homeswPin) == LOW && digitalRead(dwnlimitswPin) == LOW) {
- // drives motor up
- digitalWrite(upoutputPin, LOW);
- //at home
- (digitalRead (homelimitswPin) == 0);
- //turn motor off
- digitalWrite(upoutputPin, HIGH);
- }
- else
- // at home with home switch on stay here
- (digitalRead(homeswPin) == LOW && digitalRead(homelimitswPin) == LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement