Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Button Sequence question on: January 28, 2013, 05:15:55 pm
Awesome, thanks a ton
2  Using Arduino / Programming Questions / Re: Button Sequence question on: January 28, 2013, 02:05:46 pm
Not familiar with edge detection, do you mean just a state change detection?  If I used that, I would still need a slight delay on it, right?  I appreciate all the help, I'm an artist not an engineer, sometimes it's like reading chinese!  F.Y.I., the end goal is to build a box with a lid that looks like a Nintendo controller, and the box can only be opened by entering the Konami code, should be pretty awesome.
3  Using Arduino / Programming Questions / Re: Button Sequence question on: January 26, 2013, 03:12:05 pm
Yeah this is just mainly a proof of concept code so that I can understand the interaction of arrays, the 300ms delay after each button press does a decent job of keeping the numbers from repeating(provided they're not held down).  I'm not sure if it's good form, but it works for this test.  In the future, on my final project, I'll have a proper debounce.
4  Using Arduino / Programming Questions / Re: Button Sequence question on: January 26, 2013, 02:30:05 pm
Not really.  I only need it to do a check once all characters in the code have been entered.  Sorry about the format, new to forums.  I'll try and fix it.
5  Using Arduino / Programming Questions / Re: Button Sequence question on: January 26, 2013, 02:16:19 pm
Okay, hammered out something, It kind of works, am I at least on the right track?
Code:
const int greenled = 11;
const int redled = 8;
const int b1 = 2;
const int b2 = 3;
const int b3 = 4;

int pwcount;
byte combination[] = "1332";
byte userInput[4];

int buttonstate1 = 0;
int buttonstate2 = 0;
int buttonstate3 = 0;

void setup() {
  pinMode(greenled, OUTPUT);
  pinMode(redled, OUTPUT);
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  pinMode(b3, INPUT);
  Serial.begin(9600);
}

void loop(){
  buttonstate1 = digitalRead(b1);
  buttonstate2 = digitalRead(b2);
  buttonstate3 = digitalRead(b3);

  if (buttonstate1 == HIGH){
    userInput[pwcount] = '1';
    pwcount++;
    delay(300);
    Serial.print('1');
  }
  if (buttonstate2 == HIGH){
    userInput[pwcount] = '2';
    pwcount++;
    delay(300);
    Serial.print('2');
  }
  if (buttonstate3 == HIGH){
    userInput[pwcount] = '3';
    pwcount++;
    delay(300);
    Serial.print('3');
  }
  for(byte n = 0; n <=4; n++){


    if (userInput[pwcount] == combination[n] && pwcount >=4){
      digitalWrite(redled, LOW);
      digitalWrite(greenled, HIGH);
      Serial.println("unlocked");
      pwcount = 0;

    }
    else {
      if(userInput[n] != combination[n] && pwcount >=4){
        digitalWrite(greenled, LOW);
        digitalWrite(redled, HIGH);
        Serial.println("Denied");
        pwcount = 0;
        n = 0;
      }
    }
  }
6  Using Arduino / Programming Questions / Re: Button Sequence question on: January 25, 2013, 07:59:24 pm
One more thing, how do you store each button press in the array to be able to compare it?
7  Using Arduino / Programming Questions / Re: Button Sequence question on: January 24, 2013, 05:38:57 pm
Yes that definitely helps!  Thank you!  I'm just starting out, so learning the more complex operations is tough, being self taught, but like the beatles say, I'll get by with a little help from my friends!
8  Using Arduino / Programming Questions / Re: Button Sequence question on: January 24, 2013, 03:36:25 pm
Right, thanks for the response.  I've already got the debounce down and the basics, it's the storing in an array and comparing that I'm totally lost about. Thanks again.
9  Using Arduino / Programming Questions / Button Sequence question on: January 24, 2013, 02:31:53 pm
Hey guys!  I'm most definitely a noob and need help with this:  I want to create a simple button sequence to input to unlock something.  I'm not sure how to put it into the arduino language.  For example, let's say I have five buttons named "1-5" and I want the user to have to press them in this order (1,1,1,4,2,5,5,3)  How can I accomplish this in code?  Is it an array? a string?  Like I said, I'm green, so be gentle, I'd really appreciate the help.
Pages: [1]