Question
this is the FSM Question 1: Fill in the missing code and upload the code to your Arduino. #include Servo myservo; enum{Idle,Degree0,Degree180}; enum{IdleDC,Forward,Backward}; int DC1
this is the FSM
Question 1: Fill in the missing code and upload the code to your Arduino.
#include
Servo myservo;
enum{Idle,Degree0,Degree180};
enum{IdleDC,Forward,Backward};
int DC1 =9;
int DC2 =10;
int LED =8;
int SB=6;
int CB=5;
int FB=4;
int BB=3;
int current;
int currentDC;
void setup() {
Serial.begin(9600);
pinMode(DC1,OUTPUT);
pinMode(DC2,OUTPUT);
pinMode(LED,OUTPUT);
pinMode(SB,INPUT_PULLUP);
pinMode(CB,INPUT_PULLUP);
pinMode(FB,INPUT_PULLUP);
pinMode(BB,INPUT_PULLUP);
myservo.attach(11);
current=Idle;
currentDC=IdleDC;
}
void loop() {
switch(current){
case Idle:
Serial.println("Idel Servo is on");
delay(100);
digitalWrite(LED,LOW);
myservo.write(90);
delay(1000);
if (digitalRead(SB)==0){
delay(200);
current=Degree0;
}
if (digitalRead(CB)==0){
delay(200);
DCFSM();
}
break;
case Degree0:
Serial.println("0 degree Servo is on");
delay(100);
digitalWrite(LED,LOW);
myservo.write(0);
delay(15);
if (digitalRead(SB)==0){
delay(1000);
current=Degree180;
}
if(digitalRead(CB)==0){
DCFSM();
}
break;
case Degree180:
Serial.println("180 degree Servo is on");
delay(100);
digitalWrite(LED,LOW);
myservo.write(180);
delay(15);
if (digitalRead(SB)==0){
delay(100);
current=Idle;
}
if(digitalRead(CB)==0){
DCFSM();
}
break;
}
}
void DCFSM(){
while(true){
switch(currentDC){
case IdleDC:
Serial.println("LED is ON");
delay(100);
digitalWrite(DC1,LOW);
digitalWrite(DC2,LOW);
digitalWrite(LED,HIGH);
if(digitalRead(FB)==0){
currentDC=Forward;
}
if(digitalRead(BB)==0){
currentDC=Backward;
}
break;
case Forward:
Serial.println("Forward Motor is ON");
digitalWrite(LED,LOW);
digitalWrite(DC1,HIGH);
digitalWrite(DC2,LOW);
delay(3000);
currentDC=IdleDC;
break;
case Backward:
Serial.println("Backward Motor is ON");
digitalWrite(LED,LOW);
digitalWrite(DC1,LOW);
digitalWrite(DC2,HIGH);
delay(3000);
currentDC=IdleDC;
break;
}
if(digitalRead(SB)==0){
break;
}
}
}
Record your results in the table below:
Question 2: Modify the code to have the motor operating at half of its speed.
led servo led DC1,DC2 idle IdleDC 100 SB CB SB FB Degree0 01 30s I 30s Forward 010 SB SB Backward Degree190 01 001 Input/Output Expected Functionality Observed Functionality FSM1) Servo motor (FSM1 ervo inotOT LED (FSM1) LED (FSM2) DC motor (FSM1) DC motor (FSM2) led servo led DC1,DC2 idle IdleDC 100 SB CB SB FB Degree0 01 30s I 30s Forward 010 SB SB Backward Degree190 01 001 Input/Output Expected Functionality Observed Functionality FSM1) Servo motor (FSM1 ervo inotOT LED (FSM1) LED (FSM2) DC motor (FSM1) DC motor (FSM2)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started