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
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