0

I am a complete beginner with very little knowledge. I am trying to do a switch in Arduino UNO using a guide I found on the internet but it won't compile. The servo motor should function if it is switched on loadstate == HIGH. I have no idea what "exit status 1" is or how to fix it, help.

#include <Servo.h>
    Servo myservo;

    int buttonPin = 3;
    int reading;
    int state = 0;
    int Loadstate = 0;

    int pos = 0;
    int trig = 13; 
    int echo = 11;

void setup() {
  // put your setup code here, to run once:

    pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);
    pinMode (trig ,OUTPUT);
    pinMode (echo ,INPUT);
    myservo.attach(7);

}


void loop() {

    long duration, distance;

    digitalWrite (trig, LOW);
    delayMicroseconds (2);
    digitalWrite (trig, HIGH);
    delayMicroseconds (10);
    digitalWrite (trig, LOW);
    duration = pulseIn(echo, HIGH);
    distance = (duration/2) / 29.1;


      reading = digitalRead(buttonPin);

  if (state == 0 && reading == HIGH){
        state = 1;
        Loadstate = !Loadstate;
  }
  if (state == 1 && reading = LOW){
        state = 0;
  }

  if (Loadstate == HIGH){
      if (distance <= 30 && distance >= 0){
          for (pos = 0; pos<90; pos +=1){               

            myservo.write(pos);
            delay(15);
        }

        delay(1000);

          for(pos = 90; pos>=1;pos-=1){
            myservo.write(pos);
            delay(15);
        }
        }
        }   
}
1
  1. ledPin is not defined. You should define it somewhere.
  2. if (state == 1 && reading = LOW){ is not valid syntax. You need to use == not = to compare values.

Not the answer you're looking for? Browse other questions tagged or ask your own question.