help noob with variables
trying build home security system 3 or more states(armed away, disarmed, armed stay). code compiles without errors var "state" doesn't change when button on keypad pressed.
any appreciated
any appreciated
code: [select]
#include <lcd4bit.h>
lcd4bit lcd = lcd4bit(2);
void setup() {
lcd.init();
lcd.commandwrite(0x0f);
}
int state = 1;
int keyvalue = 0;
int password = 0;
void loop() {
serial.begin(9600); //debuging purposes only
//=================================================================================================================================
//=====================================================================disarmed====================================================
//=================================================================================================================================
while(state == 0)
{
lcd.clear();
lcd.cursorto(1,4);
lcd.printin("disarmed");
delay(1000);
return;
}
//=================================================================================================================================
//=====================================================================armed away==================================================
//=================================================================================================================================
while(state == 1)
{
lcd.cursorto(1,3);
lcd.printin("armed away");
//=====================check key===================================================================================================
int keyvalue = analogread(0);
switch(keyvalue)
{
case 31:
(password = password + 1);
}
//==================change state===================================================================================================
if (password == 1)
{
lcd.clear();
int state = 0;
}
return;
}
//===================================================================================================================================
//=====================================================================armed stay====================================================
//===================================================================================================================================
while(state == 2)
{
lcd.clear();
lcd.cursorto(1,3);
lcd.printin("armed stay");
delay(1000);
return;
}
}//end void loop
i'd recommend write out, in plain english sentences, needs done. probably on computer you'll able edit, insert , delete steps involved complete task.
do , post have have in way of outline both , wishes can reference during development,
my second recommendation not use numbers directly in source , instead use constants , or enum. numbers don't suggest being used for. example:
enum { disarmed = 0, armed_and_present, armed_and_away };
can used define label more meaningfully suggest function numbers 0, 1 , 2 states.
do , post have have in way of outline both , wishes can reference during development,
my second recommendation not use numbers directly in source , instead use constants , or enum. numbers don't suggest being used for. example:
enum { disarmed = 0, armed_and_present, armed_and_away };
can used define label more meaningfully suggest function numbers 0, 1 , 2 states.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help noob with variables
arduino
Comments
Post a Comment