Question

In C, if you are using interrupts for when a button is pressed, how would you...

In C, if you are using interrupts for when a button is pressed, how would you use the value you stored in interrupt 1 when (button 1 was pressed) to interrupt 2 when (button 2 was pressed)?

example,

If I press button 1, and the value I have is 5. How would I transfer the value (v = 5) in interrupt 1 to interrupt 2 when I press the button 2 to place in an equation T = 26 + v and then take the value of T and transfer it to interrupt 1 when I press button 1.

Homework Answers

Answer #1

Lets see the answer :-

Lets see program :-

const byte ledPin = 1;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink1, CHANGE);
}

void loop() {
  digitalWrite(ledPin, state);
}

void blink1() {
state = !state;
}

From the first line, we can see that by setting the appropriate value of button numbers, and associtating related interrupting fuctions we can achieve the said functionality.

Know the answer?
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
Similar Questions
Using pulse width modulation and interrupts create a code in adruino where you will push a...
Using pulse width modulation and interrupts create a code in adruino where you will push a button on the MCU which triggers an interrupt. Once triggered, the LED on the development board must fade-in (min to max intensity) for 2 seconds, stay at maximum brightness for 5 seconds, and then fade-out (max brightness to off) with a duration again of two seconds. cannot make use of "delay" or equivalent routines to implement the 2 or 5 second intervals but must...
Use principles of physics to solve the problem and then verify your answer using the simulation....
Use principles of physics to solve the problem and then verify your answer using the simulation. (a) What is the voltage of the battery in this simulation? V (b) When the simulation is first loaded the time constant is 8.0 seconds. What happens in this time? Select all the statements below that apply. Take V0 to be the battery voltage. If the capacitor starts off completely discharged, the time constant is the time required to fully charge the capacitor once...
Explean: 1-When connecting a button to Arduino, explain why a pull down resistor is required for...
Explean: 1-When connecting a button to Arduino, explain why a pull down resistor is required for correct operation? 2-digitalWritre (pin, state): have mention what type of value the variable state and pin can take? 3-Briefly explain the purpose of setup()and loop()function in an Arduino program? 4-Briefly explain what comparator does? 5- Briefly explain how button debouneing can affect the input read from Arduino?
How do I know the limit of convergence when x_(k+1) is in terms of x_k. For...
How do I know the limit of convergence when x_(k+1) is in terms of x_k. For example If the equation for the limit is just in x_k's how would you take the limit from k to infinity when the actual values of xk is unknown.
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
When using the Ampere Maxwell equation, are you supposed to integrate the flux first, or take...
When using the Ampere Maxwell equation, are you supposed to integrate the flux first, or take the time derivative first. I had assumed that the integration of the flux would have to happen first, but I'm seeing someone take the time derivative first, and then integrating. I'm using the integral form of the equation. Please help me understand what I'm missing. Thank you!
1.How would you analyze real options? 2.What type of projects would be in need of using...
1.How would you analyze real options? 2.What type of projects would be in need of using real options? Name an example of a project where the use of real options analysis would be beneficial.
When looking at a graph how do you know if it is zero order, first order,...
When looking at a graph how do you know if it is zero order, first order, second order. Would I be right to assume that if the y axis, would be In HOF for first order, HOF for zero order, and 1/HOF for second order. Would the equation y = mx+b change. For example y = -0.17x-0.61 change? What would be an example of the equation for zero, first and second order?
Derive an equation for calculating how many hashes it would take to find a hash value...
Derive an equation for calculating how many hashes it would take to find a hash value under a particular value for SHA-256. So for example, if you have some ceiling value x, f(x) should tell us the probability that a hash of a random message would be below the value x. For example, if x=1, then only a hash value of 0 would result in something under that value, for 1/(2^256). If you cannot derive the equation, then try calculating...
How would I use given data to generate lags? For example, I am given the variable...
How would I use given data to generate lags? For example, I am given the variable DMortgage. How would I generate lags of DMortgage(t): DMortgage (t-1), DMortgage (t-2), DMortgage (t-3), and DMortgage (t-4)?