Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Hardware: Two buttons with GPIO pullup resistors. / / The LCD. / / / / / / Problem Statement: Build an Arduino project
Hardware: Two buttons with GPIO pullup resistors.
The LCD.
Problem Statement: Build an Arduino project that uses two buttons and the LCD. One button will
clear the LCD and reinitialize counter variable to zero. If button pushed, clear LCD and counter
The second button will enter a while loop and increment the counter variable by one
and display value on LCD. While button pushed, counter counter and write counter
value to display.
Note: bit integer range of to Then rolls over to zero.
Pseudocode Algorithm
create a global integer variable counter and initialize to zero
setup
set pin as input for button one with a pullup resistor
set pin as input for button two with a pullup resistor
setup pins for LCD use Lab as your guide
loop
if button one pushed
clear LCD command from Lab
counter
while button two pushed
counter counter
write counter value to LCD commands from Lab
end while loop
end loop
Question: What is smallest value you can get for count variable shortest time pushed button two
Question: What is highest value you can get for count variable longest time push button two
Question: Change program so the counter variable subtracts one, instead of adds one. What is smallest negative value you can get for count variable longest time button two pushed
CHEGG'S CODE ANSWER PROVIDED IS AS FOLLOWS:
Based on the provided pseudocode algorithm, let's translate it into an Arduino sketch:
#include
Define LCD pins
LiquidCrystal lcd;
Global counter variable
int counter ;
void setup
Set up LCD
lcd.begin;
Set up button pins with pullup resistors
pinMode INPUTPULLUP; Button
pinMode INPUTPULLUP; Button
void loop
Check if button one is pushed
if digitalRead LOW
Clear LCD and reset counter
lcd.clear;
counter ;
Check if button two is pushed
while digitalRead LOW
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
Explanation:
The LiquidCrystal library is used for interfacing with the LCD.
In the setup function, pins for buttons and LCD are initialized.
The loop function continuously checks the state of buttons.
If button one is pushed, it clears the LCD and resets the counter to zero.
If button two is pushed, it enters a while loop, incrementing the counter and displaying it on the LCD until the button is released.
A delay of milliseconds is included to avoid rapid counting due to button bouncing.
THE BREADBOARD AND CIRCUIT HAS BEEN WIRED CORRECTLY. THIS IS WHAT IS HAPPENING: THE BUTTON CONNECTED TO PIN IS RESETTING AND CLEARING THE LCD IT SHOULD BE PIN PER THE CODE THE BUTTON CONNECTED TO PIN DOES NOTHING AS OF NOW. ALSO, THE LCD BEGINS COUNTING CONTINUOUSLY BY AS SOON AS THE CODE IS UPLOADED TO THE BOARD. PRESSING PIN RESETS THE LCD BACK TO ZERO, THEN THE LCD AGAIN BEGINS AUTOMATICALLY COUNTING UP BY ON ITS OWN WITH NO BUTTON INITIATING THE COUNTING. THANK YOU!
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