Question: This code is for Arduino. It requires an .ino file Provided motor test code: void setup() { //Setup right motor pinMode(6, OUTPUT); //Initiates right motor

This code is for Arduino. It requires an .ino file

This code is for Arduino. It requires an .ino file Provided motor

Provided motor test code:

void setup() {

//Setup right motor

pinMode(6, OUTPUT); //Initiates right motor pin

pinMode(7, OUTPUT); //Initiates right brake pin

//Setup left motor

pinMode(9, OUTPUT); //Initiates left motor pin

pinMode(8, OUTPUT); //Initiates left brake pin

}

void loop(){

//Right motor forward @ full speed

digitalWrite(6, HIGH); //Establishes forward direction of right motor

digitalWrite(7, LOW); //Disengage the right brake

analogWrite(5, 255); //Spins the right motor at full speed

//Left motor backward @ half speed

digitalWrite(9, LOW); //Establishes backward direction of left motor

digitalWrite(8, LOW); //Disengage the left brake

analogWrite(10, 123); //Spins the left motor at half speed

delay(3000);

digitalWrite(7, HIGH); //Engage the right brake

digitalWrite(8, HIGH); //Engage the left brake

delay(1000);

//Right motor forward @ full speed

digitalWrite(6, LOW); //Establishes backward direction of right motor

digitalWrite(7, LOW); //Disengage the right brake

analogWrite(5, 123); //Spins the right motor at half speed

//Left motor forward @ full speed

digitalWrite(9, HIGH); //Establishes forward direction of left motor

digitalWrite(8, LOW); //Disengage the left brake

analogWrite(10, 255); //Spins the left motor at full speed

delay(3000);

digitalWrite(7, HIGH); //Engage the right brake

digitalWrite(8, HIGH); //Engage the left brake

delay(1000);

}

Write an arduino code that uses a pin-change interrupt to implement an "Emergemcy Stop Button". Apply this to your motor testing code, The main loop should run your motor test code, doing two modes (or more) and repeating. The interrupt should trigger when pin 2 changes state. Wire a switch (provided) to pin 2 and ground, and enable the pull-up resistor in software. For the motors to stay stopped, make a "flag" or "state" variable that you check inside the motor driver code so it does not run the motors if the flag is set (=1) but does run them if not set (=0) The interrupt function be called when the pin changes state: - if pin 2 is 5V, set the flag =0 for not stopping - if pin 2 is 0V (closed), the motors should stop. - Set the flag =1 to prevent the motors from driving - You will also need to directly set the motor pins to stop the motors, so that it does not need to wait for any delay() function calls to finish

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!