Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Need help with simple 'once every hour' program

$
0
0

Hey all, I'm having some trouble with a project that checks a pin every hour and should trip a relay if a certain pin is HIGH.

 

Some notes:

- this is with the MSP430G2553 chip

- it seems to run fine if duration is low (ex: 5000ms)

- it worked at least once (triggered buzzer after an hour) when I replaced the relay circuit with a simple buzzer

 

I'm using this relay circuit:

 Arduino-automatic-blind-hooked-up-circui

And this code using TwoMsTimer library:

#include <TwoMsTimer.h>
                         
unsigned long duration = 3600000;
int relayPin = 14;
int moistPin = 15;
int state = 0;

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(moistPin, INPUT);
  digitalWrite(relayPin, LOW); // necessary bc energia sets green led HIGH by default?
  TwoMsTimer::set(duration, checkMoisture);
  TwoMsTimer::start();
}

void loop() {
  if (state == 1) {
     state = 0; // set state back to zero
     digitalWrite(relayPin, HIGH);
     delay(500);
     digitalWrite(relayPin, LOW);
  }
}

void checkMoisture() {
  if(digitalRead(moistPin) == HIGH) {
     // set state to 1 to trip relay next time loop runs
     state = 1;
  }
}

Any help is much appreciated.

 

Thanks,

Matt


Viewing all articles
Browse latest Browse all 2077

Trending Articles