Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

How has the competition changed within the last three years?

Answered: 1 week ago