Code not woking correctly and i dont know why it wont run the last if statement

//btw im uing arduino richshield on windows 10.

#include "Display.h"

const int LEDRED = 4;
const int LEDGREEN = 5;
const int LEDBLUE = 6;
const int LEDYELLOW = 7;
const int key1 = 8;
const int key2 = 9;
String ePassword;

int Password = 1234;
int lastButtonState = HIGH;
int CNUM = 1;

int buttonstate = HIGH;

int input1;
int input2;
int input3;
int input4;
int state = 0;
int mode = 1;
void setup()
{
pinMode(LEDRED, OUTPUT);
pinMode(LEDGREEN, OUTPUT);
pinMode(LEDBLUE, OUTPUT);
pinMode(LEDYELLOW, OUTPUT);
pinMode(key1, INPUT_PULLUP);
pinMode(key2, INPUT_PULLUP);
Display.show("----");

delay(1500);
Serial.begin(9600);

}

void Key1_Action() {

int state = 0;
int button1 = digitalRead(key1);
int lastbuttonstate;
if (button1 != lastbuttonstate && buttonstate == LOW) // if button 1 is pressed.
{
CNUM++;
Serial.println(CNUM);
if (CNUM > 5) {
CNUM = 1;
delay(150);
}

}
if (buttonstate != button1) {
buttonstate = button1;

}
}

void loop()
{

if (mode == 1) {
Key1_Action() ;
int button2 = digitalRead(key2);
Display.showCharAt(0, '0' + CNUM);
if (button2 == LOW) {
//digitalWrite(LEDRED, HIGH);
int input1 = CNUM;
Display.showCharAt(0, '0' + input1);
mode++;
delay (1000);
}
}
if (mode == 2) {
Key1_Action() ;
int button2 = digitalRead(key2);
Display.showCharAt(1, '0' + CNUM);
if (button2 == LOW) {
//digitalWrite(LEDRED, HIGH);
int input2 = CNUM;
Display.showCharAt(1, '0' + input2);
mode++;
delay (1000);
}
}
if (mode == 3) {
Key1_Action() ;
int button2 = digitalRead(key2);
Display.showCharAt(2, '0' + CNUM);
if (button2 == LOW) {
//digitalWrite(LEDRED, HIGH);
int input3 = CNUM;
Display.showCharAt(2, '0' + input3);
mode++;
delay (1000);
}
}
if (mode == 4) {
Key1_Action() ;
int button2 = digitalRead(key2);
Display.showCharAt(3, '0' + CNUM);
if (button2 == LOW) {
//digitalWrite(LEDRED, HIGH);
int input4 = CNUM;
Display.showCharAt(3, '0' + input4);
mode++;
delay (1000);
}
}
if (mode == 5) {
//String ePassword = String(input1 + (input2 * 10) + (input3 * 100) + (input4 * 1000));
String ePassword = String(input1 + input2 + input3 + input4);
int button2 = digitalRead(key2);

//toInt(ePassword);
//toInt(Password);
if (ePassword.equals(Password))  {
  digitalWrite(LEDGREEN, HIGH);
  digitalWrite(LEDRED, LOW);
  digitalWrite(LEDBLUE, LOW);
  digitalWrite(LEDYELLOW, LOW);
  Display.show(ePassword);
  delay (1000);

}
if (ePassword.equals(Password)) 
{
  digitalWrite(LEDGREEN, LOW);
  digitalWrite(LEDRED, HIGH);
  digitalWrite(LEDBLUE, LOW);
  digitalWrite(LEDYELLOW, LOW);
  Display.show("Err");
  delay (1000);
}

}
}

You didn't give it a value.

Please remember to use code tags when posting code

I try to avoid String, but "Password" is an "int" - is that expected to work?

i think i found anther problem. when i asked the display to only show input1 it displayed 0 as in it didnt have a value.

I'm not sure what you expect, but you may have a scope issue with "input1"

1 Like

i know its way late but you were correct that was the problem

so can you fix post #1 now and add code tags please? (please read How to get the best out of this forum ).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.