Hello! The codes below is what I want to happen. But before that, I need first to set a passcode by pressing buttons.
for example my passcode would be switches 1,4 and 3. Then it will proceed to run the below codes. If I entered incorrect password (132), then all LED’s will on then off. Then I can try another passcode. It has 6 switches, 1 for reset and 8 LED’s.
Please help me on the codes
Thanks a lot!
int timer = 100;
int ledPins = {
13,12,11, 10, 9, 8, 7, 6};
int pinCount = 8;
void setup() {
Put the button press detection in setup as a while loop:
void setup(){
pinMode (pinX, INPUT_PULLUP); // button with internal pullup resistor, connect to Gnd when pressed
//other setup stuff, like Serial.begin, SPI.begin, etc.
:
:
// last thing:
while (digitalRead(pinX) == HIGH){
// hang out waiting for a LOW
}
// LOW received, proceed
}
int buttonTest1=bPress(1);
if(buttonTest1==0) mode++;
int buttonTest2=bPress(2);
if(buttonTest2==0)digitalWrite(ledPin[1], HIGH);
else digitalWrite(ledPin[1], LOW);
THANKS a lot! Really big help
It's also my project, my teacher also added, if any of the 5 random buttons he press, it will proceed to the main program.
Hi guys, I need help in this matter I need 3 passcode buttons before proceeding to the main program. Below are my codes. I had already made 1 passcode, I have trouble on where and how will I add another two passcodes. Please help I really need this right now =(
int timer = 100;
int ledPins = {
13,12,11, 10, 9, 8, 7, 6};
int pinCount = 8;
int buttonPin = 0;
int ledPin =13;
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, LOW);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin–) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
}
}
sharmane18:
Hi guys, I need help in this matter I need 3 passcode buttons before proceeding to the main program. Below are my codes. I had already made 1 passcode, I have trouble on where and how will I add another two passcodes. Please help I really need this right now =(
int timer = 100;
int ledPins = {
13,12,11, 10, 9, 8, 7, 6};
int pinCount = 8;
int buttonPin = 0;
int ledPin =13;
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, LOW);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin–) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
}
}
sry not reply on time. i am a newbie too, normally I come here to ask for help. in your case about adding a pass-code. I suggest that you add 3 values to your code.
when one button is pressed, value1=1;
then if another button is pressed , if value1==1, value2=1; else value1=0; value2=0;
then if last button is pressed , if (value1==1 && value2==1) value3=1; else value1=0; value2=0; value3=0;
&& this means and; only if value1 and value2=1, value3 will equal 1
then last do this if(value1==1 && value2==1 && value3==1 ) then { go to the main program screen}