Question

In: Computer Science

Using the first code of this lab (Figure 1), write a code that displays the status...

Using the first code of this lab (Figure 1), write a code that displays the status of a push button on the LCD, that is, when you press it you should see “Pushed” on the LCD and when you release it, you should see “Released”

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

}

void loop() {

// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

lcd.print(millis() / 1000);

}

This is supposed to run on an Arduino. Thanks for your help!

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: In my circuit, I have attached push button to digital pin 7 on arduino. check the diagrams attached. bottom left terminal of button is connected to pin 7 as well as to a 10K resistor, which is connected to the ground (GND), bottom right terminal is connected to 5V pin.



// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//pin number where button is connected.
//change it if your button is connected to a different pin
const int buttonPin=7;
//state of the button
int btnState=0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  //reading button state
  btnState=digitalRead(buttonPin);
  //if state is HIGH, printing Pushed on LCD, else printing
  //Released
  if(btnState==HIGH){
        lcd.print("Pushed  ");
  }else{
        lcd.print("Released");
  }
  delay(50); //giving a slight delay
}
 

/*Circuit Diagram & OUTPUT*/


Related Solutions

using math lab, Write a code to compute the change in dollars (no cents) to be...
using math lab, Write a code to compute the change in dollars (no cents) to be given back to a restaurant patron who pays the bill in cash. That is, find and enumerate the various combinations (of common currency notes only) that can amount to the change due.
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
Write the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
c++ Write a program that displays the status of an order. a) Program uses 2 functions...
c++ Write a program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display...
1. How do I write a query that displays the name (concatenate the first name, middle...
1. How do I write a query that displays the name (concatenate the first name, middle initial, and last name), date of birth, and age for all students? Show the age with no decimal places, and only include those students who are 21 or older. Order by age, as shown below: (Hint: Use the TRUNC function. The ages may be different, depending on the date that the query is run.) SELECT S_FIRST || ' ' || S_MI || ' '...
How to create a JS application using the code below that displays the lists of grades...
How to create a JS application using the code below that displays the lists of grades in their corresponding letter grade textbox and each grade being sorted from lowest to highest. <!DOCTYPE> <html> <head> <title>EXAM01_03</title> <style type="text/css"> form{color:black;background-color:lightgray;border:6px solid black;border-width:4px;width:450px;margin:1px;padding:1px;} #ans1,#ans2,#ans3,#ans4,#ans5,#numbers{background-color:white;border:4px solid black;} input[type="button"]{color:black;background-color:red;border:4px solid black;} input[type="text"]{margin:2px;} div.title{color:white;background-color:black;float: left; width: 450px; text-align:center;} </style> </head> <body>    <form>    <div class="title"><label>EXAM01_03</label></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>Enter Grade List:</label></div><div style="float:left;"><input type="text" id="numbers" /></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>A:</label></div><div...
write a code using c++. Find the first 10 prime numbers and store them in an...
write a code using c++. Find the first 10 prime numbers and store them in an array.
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
Write the MATLAB code to Create a new figure. Define a theta array such that ?...
Write the MATLAB code to Create a new figure. Define a theta array such that ? 2 ≤ ? ≤ 9? 2 with increment of ? 10 ; Create a sixmember array of ones called r. Create a new polar plot of ? versus r
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT