Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below is the Arduino code which is working as assigned. Button 1 is attached to Pin 4 . Button 1 ( Pin 4 ) when
Below is the Arduino code which is working as assigned. Button is attached to Pin Button Pin when pressed is clearing the LCD and resetting the counter to zero. Button is attached to Pin Button Pin when held down is incrementing the LCD counter continuously by it is inside a while loop Within the code, both pin & digital reads are set to HIGH, instead of LOW. This was necessary to achieve the desired output given the wiring and circuit board. However, this appears to be backwards, as the pressing the buttons should pull the input resistor to ground and creating a LOW state. Why would the code work as assigned if the button digital reads are set to HIGH instead of LOW? Thank you, code follows.....
#include
Define LCD pins
LiquidCrystal lcd;
Global counter variable
int counter ;
void setup
Set up LCD
lcd.begin;
lcd.clear;
counter ;
Set up button pins with pullup resistors
pinMode INPUTPULLUP; Button
pinMode INPUTPULLUP; Button
void loop
Check if button one is pushed
while digitalRead HIGH
Clear LCD and reset counter
lcd.clear;
delay;
lcd.setCursor;
lcd.printCounter: ;
counter ;
Check if button two is pushed
while digitalRead HIGH
Increment counter
counter;
Write counter value to LCD
lcd.setCursor;
lcd.printCounter: Stringcounter;
delay; Add a delay to avoid rapid counting due to button bouncing
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