Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
3
Indexable
Never
#define modeSwitch 2

#define in1 7
#define in2 8
#define enA 5 
#define enB 6
#define stby 3

void forward(){
  digitalWrite(in1, HIGH);
  digitalWrite(in2, HIGH);
  analogWrite(enA, 75);
  analogWrite(enB, 75);
}

void backward(){
  digitalWrite(in1, LOW); 
  digitalWrite(in2, LOW);
  analogWrite(enA, 75);
  analogWrite(enB, 75); 
}

void right(){
  digitalWrite(in1, LOW); 
  digitalWrite(in2, HIGH);
  analogWrite(enA, 50);
  analogWrite(enB, 50);
}

void left(){
  digitalWrite(in1, HIGH); 
  digitalWrite(in2, LOW);
  analogWrite(enA, 50);
  analogWrite(enB, 50);
}

void stop(){
  digitalWrite(in1, LOW); 
  digitalWrite(in2, LOW);
  analogWrite(enA, 0);
  analogWrite(enB, 0);
}


void setup() 
{

  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(stby, OUTPUT);
  pinMode(modeSwitch, INPUT_PULLUP);
  delay(30000);

}


void loop() 
{
    
    while(digitalRead(modeSwitch) == 1) {
      delay(30000);
      
      digitalWrite(stby, HIGH);

      forward();
      delay(5000);

      backward();
      delay(5000);

      right();
      delay(5000);

      left();
      delay(5000);

      stop();
      delay(10000);


    }
}





Leave a Comment