storing a value?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
mbrown9412
 
Posts: 7
Joined: Mon Nov 22, 2010 11:17 pm

storing a value?

Post by mbrown9412 »

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?

User avatar
stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: storing a value?

Post by stinkbutt »

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.

mbrown9412
 
Posts: 7
Joined: Mon Nov 22, 2010 11:17 pm

Re: storing a value?

Post by mbrown9412 »

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?

User avatar
stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: storing a value?

Post by stinkbutt »

Code: Select all


volatile unsigned int code = 12345;

setup()
{
// Do stuff
}

loop()
{
// Do more stuff
}


mbrown9412
 
Posts: 7
Joined: Mon Nov 22, 2010 11:17 pm

Re: storing a value?

Post by mbrown9412 »

ok, then in the loop procedure, how would i make it check that?

User avatar
stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: storing a value?

Post by stinkbutt »

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?

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”