mercredi 27 juillet 2016

Adruino newbie trying to figure out how to make conditional moves based on inputs.

I am building a chicken egg rocker “Incubator” This is my first attempt with a Arduino projects but I have programmed PLC’s for years. I have run into problems: The top section of code (find home sequence when switched) I can’t get to run but it compiles, I am lost on this I am not sure if I missed some syntax some ware? I wanted to build some subroutines to jump to that both sections of code could access similar to PLS’c but see this is a no no (the goto command). I would appreciate some direction if anyone is willing. I do have a up/down cycle timer working with limit switches timer based on pot position. The goal : when the home switch is turned on the system will figure out where it is by moving to a limit then find home. This may need to be done mid cycle to remove hatchlings (the trays have to be level / home to be removed). I thought I could accomplish this using the while command to watch the switch then stay in that section of code (at home until the switch is turned off) The verify function failed until I added extra brackets that did not look right but it would compile and load to the board. Thanks in advance.

    // 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);
}

} }

Aucun commentaire:

Enregistrer un commentaire