Arduino program problem


hello,

i wrote code (see below) if put in serial a  buzzer turns on 0,1 sec off 0,1 , repeats 1 more time after relay turns off 1 hour.

normally put relay i'm planning on adding more code later run before relay turns off couldn't use delay. instead count milliseconds , time it, led won't blink , coudn'd figure out why (newbie) hoping help.

also sorry vague title didn't know way describe problem.

code: [select]
int incomingbyte = 0;
int standby = 1;
const int beepin = 13;
const int relay = 12;
unsigned long previousmillis = 0;

void setup() {
  serial.begin(9600);
  digitalwrite(beepin, high);
  pinmode(beepin, output);
  pinmode(relay, output);
}

void loop() {


  if (serial.available() > 0) {
    incomingbyte = serial.read();

    if (incomingbyte == 97 || standby == 1 ) { //if serial input = a
      standby = 1; //sets kinda reminder there "a" recieved
      unsigned long currentmillis = millis();
      if (currentmillis >= 0 && currentmillis < 100) { //first 100 sec set pin 13 high
        digitalwrite(beepin, high);
      };
      if (currentmillis >= 100 && currentmillis < 200) { //200 sec set pin 13 low
        digitalwrite(beepin, low);
      };
      if (currentmillis >= 200 && currentmillis < 300) { //300 sec set high again
        digitalwrite(beepin, high);
      };
      if (currentmillis >= 300 && currentmillis < 400) { //last 400 sec set low
        digitalwrite(beepin, low);
        currentmillis = 0; //set timer 0 next time
        standby = 0; //turns of reminder
        digitalwrite(relay, low); //turn off relay
        delay(3600000); //wait 1 hour
        digitalwrite(relay, high); //turn relay on
      };
    };
  };
};

all of checks time inside if(serial.available()) block.  checked if there new serial data available. 

make boolean variable can set true in serial part , test see if need run timing code. 


Arduino Forum > Using Arduino > Programming Questions > Arduino program problem


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'