Question: Change your program to decrement encoderPosition every time the push-button is pressed. unsigned long ButtonTimer; long encoderPosition; int A; int B; #include LiquidCrystal LcdDriver(11, 9,

Change your program to decrement encoderPosition every time the push-button is pressed.

unsigned long ButtonTimer;

long encoderPosition;

int A;

int B;

#include

LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8 );

void MonitorA()

{

if (A == B) {

encoderPosition++;

}

else

{

encoderPosition--;

}

}

void MonitorB() {

if (A == B)

{

encoderPosition--;

}

else

{

encoderPosition++;

}

}

//SetUP

void setup() {

LcdDriver.clear();

LcdDriver.begin(16, 2);

LcdDriver.setCursor(0, 0);

ButtonTimer = millis();

pinMode(2, INPUT);

pinMode(3, INPUT);

attachInterrupt ( digitalPinToInterrupt(2), MonitorA , CHANGE);

attachInterrupt (digitalPinToInterrupt(3), MonitorB , CHANGE);

}

//Loop

void loop() {

A = digitalRead(2);

B = digitalRead(3);

if (millis() - ButtonTimer >= 100) {

LcdDriver.clear();

LcdDriver.print(encoderPosition);

ButtonTimer += 100;

}

}

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!