How do I make my arduino store a value, instead of seeing if it is currently true? I want to make a passcode lock, so I could have it be where if this val = 1, if this =1, etc, etc.
also, how would I then make it so they had to be pressed in order?
storing a value?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- stinkbutt
- Posts: 593
- Joined: Wed Feb 17, 2010 2:40 am
Re: storing a value?
Make a variable that contains the code in it (outside of the setup() and loop() functions) and then check against it.
Unless you need to set the code during execution. Then you set up a function to input the code, and set the value of that variable in the function. You'll probably need to make the variable volatile so that the code always re-checks the value and doesn't use cached versions.
Unless you need to set the code during execution. Then you set up a function to input the code, and set the value of that variable in the function. You'll probably need to make the variable volatile so that the code always re-checks the value and doesn't use cached versions.
-
- Posts: 7
- Joined: Mon Nov 22, 2010 11:17 pm
Re: storing a value?
ok - say if i want to make the variable outside of the loop and setup, what do I do?
int code = 234
something like that?
int code = 234
something like that?
- stinkbutt
- Posts: 593
- Joined: Wed Feb 17, 2010 2:40 am
Re: storing a value?
Code: Select all
volatile unsigned int code = 12345;
setup()
{
// Do stuff
}
loop()
{
// Do more stuff
}
-
- Posts: 7
- Joined: Mon Nov 22, 2010 11:17 pm
Re: storing a value?
ok, then in the loop procedure, how would i make it check that?
- stinkbutt
- Posts: 593
- Joined: Wed Feb 17, 2010 2:40 am
Re: storing a value?
You're going to need to give me a whole lot more information than that. How are you obtaining this "code?" Via a keypad? An RFID tag? Carrier Pigeon?
Please be positive and constructive with your questions and comments.