1.

Solve : Need help with program language C (Using Arduino)?

Answer»

I want to make a password security system with the help of buttons on my arduino. We NEED to use 3 buttons and the password should have 4 numbers in it. If you get the code right it should light up the green light if you get it wrong it should light up the red one

I am having problems with making strings. My original idea was to make a string which contains the password ( 1231) and another string that doesnt have a VALUE. But if you press on the first button its goes unusedstring = unusedstring + 1 if you press the second button it goes unusedstring = unusedstring + 2 and if you press the third it goes unusedstring = unusedstring +3.

And if the length of unusedstring eqauls 4.
Then it should check if the unusedstring and the password are similar.
And if unusedstring is 1231 then it should light up the green one
If it got it wrong it should light up the red one. And after it does one of these 2 things it should RESET the unusedstring. So that people can try to guess the code again.



Also, just 1 guy in my class has this one, but his doesnt contains strings. He says it actualy harder to use string

MY CODE SO FAR
_______________________________________ _______________________________________ _____________________________


const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int ledPinRood = 6;
const int ledPinGroen = 7;

String GoedeCode = String("1233");
String AntwoordCode = String("");
String IngevuldeCode;
int buttonState1;
int buttonState2;
int buttonState3;
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
int lastButtonState3 = LOW;



long lastDebounceTime = 0;
long debounceDelay = 50;


void setup()
{
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(ledPinRood, OUTPUT);
pinMode(ledPinGroen, OUTPUT);

}

void loop()
{

int reading1 = digitalRead(buttonPin1);
int reading2 = digitalRead(buttonPin2);
int reading3 = digitalRead(buttonPin3);


if (reading1 != lastButtonState1 || reading2 != lastButtonState2 || reading3 != lastButtonState3)
{
if (reading1 != buttonState1)
{
buttonState1 = reading1;
if (buttonState1 == HIGH)
{
IngevuldeCode = AntwoordCode + 1;
AntwoordCode = IngevuldeCode;
}
}

if (reading2 != lastButtonState2)
{
buttonState2 = reading2;
if (buttonState2 ==HIGH)
{
IngevuldeCode = AntwoordCode + 2;
AntwoordCode = IngevuldeCode;
}
}

if (reading3 != lastButtonState3)
{
buttonState3 = reading3;
if (buttonState3 ==HIGH)
{
IngevuldeCode = AntwoordCode + 3;
AntwoordCode = IngevuldeCode;
}
}

}
}


if (IngevuldeCode.length() == 4)
{
if (IngevuldeCode == GoedeCode)
{
digitalWrite(ledPinGroen, HIGH);
delay(3000);
digitalWrite(ledPinGroen, LOW);
IngevuldeCode = "";
AntwoordCode = "";
}
else
{
digitalWrite(ledPinRood, HIGH);
delay(500);
digitalWrite(ledPinRood, LOW);
delay(500);
digitalWrite(ledPinRood, HIGH);
delay(500);
digitalWrite(ledPinRood, LOW);
delay(500);
digitalWrite(ledPinRood, HIGH);
delay(500);
digitalWrite(ledPinRood, LOW);
IngevuldeCode = "";
AntwoordCode = "";
}

}


}




If you got any question, ask me.




Discussion

No Comment Found