Behaviour that I cant explain


hi guys.

my project behaving odd , life of me, cant figure out why.

first off, code:

code: [select]
int siren = 12;
int beamled = 11;

int beam = 8; // no pushbutton during poc phase.

static unsigned long lastbeamtime = 0;

boolean alarmisactive = false;
int sirenduration;

void setup()
{
 pinmode (siren, output);
 pinmode (beamled, output);

 pinmode (beam, input);

 digitalwrite (siren, low);
 digitalwrite (beamled, low);

 digitalwrite (beam, high);
}

void loop()
{
 if (alarmisactive && (millis() - sirenduration) > 5000)
 {
 sirenduration = millis();
 alarmisactive = false;
 digitalwrite (siren, low);
 }
 else if (digitalread(beamled) == high && digitalread(beam)  == low && alarmisactive && (millis() - sirenduration) > 5000)
 {
 alarmisactive = false;
 digitalwrite (siren, low);
 }

 if (digitalread(beam) == low && (millis() - lastbeamtime) > 100)
 {
 lastbeamtime = millis();
 alarmisactive = true;
 sirenduration = millis();
 digitalwrite (siren, high);
 digitalwrite (beamled, high);
 }
}


although doing expected, problem when hits 4th cycle, pin marked "siren", no longer responds.

initially thought due debouncing, attemted cater it.
after that, though leds run without resistors, didb't solve issue, don't know.

i know code horrible, i'm still learning , sanitize understanding improved, now, want know why system ignores "siren" output though input being triggered.

please let me know if need more information required might assist in solution this.

ps. same result on both hardware simulator.

your , positive criticism appreciated.  

just hobby coder here, might wrong.

int sirenduration; (and others)

sirenduration = millis();


from millis page:
"note parameter millis unsigned long, errors may generated if programmer tries math other datatypes such ints."
leo..


Arduino Forum > Using Arduino > Project Guidance > Behaviour that I cant explain


arduino

Comments