Hi there
I simply want the following to happen...
if this event happens start a new timer each time, once that time reaches say 1 minute then do this...
i.e. once I have recorded the rainfall text it to me.
But all the different millis codes ive been trying do not work at all they either get stuck half way down my code or they reach the interval time straight away
also it tells me I havn't defined currentMillis which I undersand but the blink without delay sketch compiles on its own fine?!
#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 previousMillis = 0;
long interval = 1000;
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");
unsigned long currentMillis = millis();
}
else
{
delay(1000);//1 second inbetween tips
}
if(currentMillis - previousMillis > interval)
{
dtostrf(myval, 4, 2, str_rainfall);
sprintf(rainfall,"%smm rainfall", str_rainfall);
//if(sms.SendSMS("+27630812488", rainfall));
myval = 0;
Serial.println("SMS");
}
else
{
delay(10);
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}