logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

project that utilizes Arduino Code to control a small LCD screen. When i run it it does mot work. Can you please help me find error in code?

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

 project that utilizes Arduino Code to control a small LCD screen. When i run it it does mot work. Can you please help me find error in code?

 

The code that I have so far, a picture of the board and some feedback that I have received but didn’t work when I implemented it. Is there an error in my code? Am I missing something?

 

The project involves entering a 16 digit pass code using two buttons and seeing various results on a small LCD screen. In its current state the introduction displays on the screen but pressing the buttons does nothing

 

Code that I have so far:

#include <LiquidCrystal.h> //the LC library

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // pin locations for the LCD

 

//set pins for the buttons int button[] = {5, 7};

 

int pressedButton = 2; //a variable to remember which button is being pressed. 2 is the value if no button is being pressed.

int counter = (0); //tracks which character of the password the user is on

int buttonSequence[16] = {0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0}; //make an array of the characters that will be the password int digitsInCode = 16;

 

boolean programStart = false; //variable to tell the program whether or not to play the start sequence

 

// FUNCTIONS

 

//START SEQUENCE

void startSequence() {

 

lcd.clear(); //clear the display

lcd.setCursor(0, 0); //set the cursor to the 0,0 position (top left corner)

lcd.print("SECURITY"); //print SECURITY starting at that position lcd.setCursor(0, 1); //set the cursor to the 0,0 position (bottom left corner)

lcd.print("CHECK"); //print CHECK starting at that position delay(3000); //wait for 3 seconds

lcd.clear(); //clear the display

lcd.setCursor(0, 0); //set the cursor to the 0,0 position (top left corner)

int counter = (0);

}

 

//CHECK WHICH BUTTON IS PRESSED

int buttonCheck() {

//check if any buttons are being pressed if (digitalRead(button[0]) == LOW) { return 0;

} else if (digitalRead(button[1]) == LOW) { return 1;

} else {

return 2; //this will be the value for no button being pressed

}

}

 

//CORRECT PASSWORD SEQUENCE

 

void correctPass() {

 

lcd.setCursor(0, 1); lcd.print("Correct!");

 

delay(2000); lcd.clear();

 

lcd.setCursor(0, 0); lcd.print("CONGRATS"); lcd.setCursor(0, 1); lcd.print("YOU GOT IT RIGHT!");

}

 

//WRONG SEQUENCE

void wrongSequence() {

 

lcd.setCursor(0, 1); //move the cursor to the first space of the bottom row

lcd.print("Incorrect"); //print Incorrect at that position delay(3000); //wait for 3 seconds

programStart = false; //reset the program so that the start sequence will play again.

}

 

//

 

 

 

 

 

void setup() {

 

lcd.begin(16, 2); //tell the lcd library that we are using a display that is 16 characters wide and 2 characters high

lcd.clear(); //clear the display

 

//set the button pins as inputs pinMode(button[0], INPUT_PULLUP); pinMode(button[1], INPUT_PULLUP);

 

int counter = (0); //make a variable to count the correct characters entered by the user

 

}

 

void loop() {

 

if (programStart == false); { //if the password program hasn't started yet

startSequence(); //play the start sequence counter = 0; //reset the counter delay(1500); //wait a second and a half

programStart = true; //set programStart to true so that this sequence doesn't start again

}

 

lcd.setCursor(0, 0); //set the cursor to the 0,0 position (top left corner)

lcd.print("Enter Password:"); //print Enter Password: starting at that position

 

for (int i = 0; i <= counter; i++) {

 

while (programStart == true); //Loop until the program is false

 

pressedButton = buttonCheck(); //every loop check to see which button is pressed

 

if (pressedButton < 2) { //if a button is pressed... (2 means that no button is pressed)

 

lcd.setCursor(0, 1); //move the cursor to the first space of the bottom row

lcd.print(pressedButton); //print 0 at that position

 

if (pressedButton == buttonSequence[i]) { //if the button matches the button in the sequence

delay(250); //leave the 0 on for a moment lcd.clear();

break;

}

else { //if the wrong key is pressed wrongSequence();

break;

}

}

else { lcd.clear();

}

}

 

 

(5/5)
Attachments:

Expert's Answer

477 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

477 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

500 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

903 Answers

Hire Me
expert
Husnain SaeedComputer science

563 Answers

Hire Me
expert
Atharva PatilComputer science

637 Answers

Hire Me

Get Free Quote!

326 Experts Online