Question

In C++ (compatable with arduino) write a program that will debounce and interrupt (the interrupt ...

In C++ (compatable with arduino) write a program that will debounce and interrupt (the interrupt used is a push button) so that when you click the button once a servo motor turns to 0 degrees and when you press it twice consecutively within a 1 second interval the service motor turns 45 degrees. When pressed three times consecutively within that same one second interval it turns the servo motor 90 degrees. Pressed 4 times consecutively and the servo motor turns 180 degrees.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

For any doubts comment below.

#include <Servo.h>
  
int i = 0;
int btn=0;
int c1=0;
int laststate=0;
int currstate =0;
Servo myservo;
void setup() {
myservo.attach(9);
pinMode(13,OUTPUT);
pinMode(6,INPUT);
Serial.begin(9600);
}

void loop() { c1=0;
if(laststate==currstate){

for(i=0;i<1000;i++){
btn = digitalRead(6);
if(btn>=1)
{ delay(100);
btn = digitalRead(6);

if(btn==0)
{
c1+=1;
}
}
delay(1);
}
}

if(c1==0)
{
currstate=laststate;
}
else if(c1==1)
{
myservo.write(0);
Serial.println("0");
laststate=1;
}
else if(c1==2)
{
myservo.write(45);
Serial.println("45");
laststate=2;
}
else if(c1==3)
{
myservo.write(90);
Serial.println("90");
laststate=3;
}
else if(c1==4)
{
myservo.write(180);
Serial.println("180");
laststate=4;
}

}

Add a comment
Know the answer?
Add Answer to:
In C++ (compatable with arduino) write a program that will debounce and interrupt (the interrupt ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. Write an Arduino program to do the following function: When a switch connected to digital...

    3. Write an Arduino program to do the following function: When a switch connected to digital pin 4 is pressed, three LEDs connected to digital pins 5, 7, and 9 will blink ON and OFF sequentially (i.e. one after the other) with half a second delay between when an LED turns ON and turns OFF.

  • Build a state-machine embedded application as an Arduino sketch (program) that does the following... if the...

    Build a state-machine embedded application as an Arduino sketch (program) that does the following... if the motor is stopped, when the user pushes a push-button (which I will call INPUT1), the motor begins rotating if there is a currVelocity set, the motor rotates at this velocity if currVelocity has not been set, the motor rotates at an initial slow velocity (chosen by you) if the motor is running, when the user pushes the push-button INPUT1, the motor speeds up again...

  • please solve all the questions Q1 (30 pts) Design a state-based PLC program to control a...

    please solve all the questions Q1 (30 pts) Design a state-based PLC program to control a motor. The system specification is as follows. • Press a normally open push button, the motor will start. Motor stop will stop after 5 minutes or a normally close push button is pressed. . When the motor is running, a read light is ON. When the motor is stopped, a green light is ON. Use the "Fail Safe" concept, i.e., if the wire of...

  • Using the template provided in the lab details section, formulate a program for the Arduino to...

    Using the template provided in the lab details section, formulate a program for the Arduino to generate a PWM signal duty cycles between 0% and 100% at intervals of 10% where a button will increment the PWM signal. Remember the RC is 10 milliseconds. Provide a copy of the final code and explain how it works. Arduino PWM Example int Pin = 9; void setup() { pinMode (Pin, OUTPUT); } void loop() { analogWrite (Pin, 127); // Generate 50% duty...

  • Car Parking Sensor Build a simple Car parking sensor system using the Arduino. Use the provided U...

    i want the arduino code please We were unable to transcribe this imageCar Parking Sensor Build a simple Car parking sensor system using the Arduino. Use the provided Ultrasonic Sensor to measure the distance between the sensor and an object. When an object is detected within a defined range, a buzzer must beep repeatedly at a certain rate. And as the object gets closer, the beeping gets faster. Your design must meet the following requirements 1. Calibrate the range of...

  • Write a calculator program using JavaScript in HTML in the same HTML file. (There will only...

    Write a calculator program using JavaScript in HTML in the same HTML file. (There will only be 1 HTML file containing everything that you use for this program.) *************JavaScript Functions should be written in the HTML <head> .............. </head> tag, **************** (Please be mindful of the formatting of the text of your program. Meaning that do not copy paste everything in a single line. Add clear comments for a better understanding of your program) as follows Assignment: create a form...

  • THIS IS A PLC PROGRAM CALLED SIMATIC MANGER. WE NEED TO WRITE LADDER LOGIC PROGRAM AND FORM A SYM...

    THIS IS A PLC PROGRAM CALLED SIMATIC MANGER. WE NEED TO WRITE LADDER LOGIC PROGRAM AND FORM A SYMBOL TABLE We were unable to transcribe this imageThe painting turn-table system shown in the following figure has a DC motor, two limit switches, a pneumatic cylinder, a start button and two spray guns. The paint guns are activated by 24 V DC voltage. The motor turns the table only in one direction Red Spray gun Blue spray gun Limit switch trigger...

  • Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature...

    Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. breezypythongui.py temperatureconvert... + 1 2 File: temperatureconverter.py 3 Project 8.3 4 Temperature conversion between Fahrenheit and Celsius. 5 Illustrates the use of numeric data fields. 6 • These components should be arranged in a grid where the labels occupy the first row and the corresponding fields...

  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

  • C+ HelloVisualWorld, pages 121-125 (in the 3-6 Deciding Which Interface to Use Section) We were unable...

    C+ HelloVisualWorld, pages 121-125 (in the 3-6 Deciding Which Interface to Use Section) We were unable to transcribe this imageCHAPTER 3 Using Guy Objects and the Visual Studio IDE Using Gul Objects (continued) Forn click the Form, its Properties window appears in the lower right portion of the screen, and you can see that the Text property for the Form IS set to Forml. Take a moment to scroll through the list in the Properties Window, examining the values of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT