Hi all
This is for a rain gauge project..
Ive got a float variable counter that counts nicely. I want to add a timer to it so that if there are no switches for 5mins then send the value and an SMS and reset the counter.
Obviously i dont want to use a delay because it will not be able to count if there is another switch.
I tried using stuff out of the BlinkWithoutDelay example but it has just seemed to work in the same way as a delay because it wont count once it gets to that part. But im probably doing it wrong...
Do I need to put a timer library in for something this simple?
im just really confused about this one!!
#include <stdlib.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
// this constant won't change:
const int buttonPin = 4; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
float myval; //0.2mm multiple
int numdata;
boolean started=false;
char str_rainfall[6];
char rainfall[10];
char smsbuffer[160];
char n[20];
char sms_position;
char phone_number[20]; // array for the phone number string
char sms_text[100];
int i;
long interval = 100000;
void setup()
{
pinMode(buttonPin, INPUT); // initialize the button pin as a input:
pinMode(ledPin, OUTPUT); // initialize the LED as an output:
Serial.begin(9600); // initialize serial communication:
Serial.println ("Arduino on");
if (gsm.begin(4800));
Serial.print ("GSM on");
//if (sms.SendSMS("+27630812488", "power on"));
Serial.print("\nSMS sent OK");
Serial.println("\nGauge ready");
}
void loop()
{
char txtMsg[200];
buttonState = digitalRead(buttonPin); // read the pushbutton input pin:
if (buttonState != lastButtonState) // compare the buttonState to its previous state
{
if (buttonState == HIGH) // if the state has changed, increment the counter, if the current state is high then the circuit is open
{
myval += 0.2;
Serial.print("Rainfall: ");
Serial.print (myval);
Serial.println("mm");
}
else
{
delay(1000);//1 second inbetween tips
}
if (buttonState == LOW && myval !=0.0)
{
//interval;
dtostrf(myval, 4, 2, str_rainfall);
sprintf(rainfall,"%smm rainfall", str_rainfall);
if(sms.SendSMS("+27630812488", rainfall));
myval = 0;
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}