Hello,
I do I make sure that particle only published once. I have rpm being measured on a pump and will run the pump for 1 minute once a button is pressed.
Can someone tell me how to only send the rpm once after the pump runs for a certain time.
here is code
Thanks
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>
//define the input/output pins
//pump/relay pins
#define PUMP_IN_PIN 3
#define PUMP_OUT_PIN 2
//pushbutton pins
#define BUTTON_1_PIN 5
#define BUTTON_2_PIN 6
//Time for pumping stations to turn on in milliseconds
#define PUMP_IN_TIME 60000
#define PUMP_OUT_TIME 60000
const byte interruptPin = 4; //digital pin for hall effect
volatile unsigned long halltime, halllast, hallinterval; // timing variables
int rpm;
int pulsecount;
//Ubidots info
// //Ubdiots
#ifndef TOKEN
#define TOKEN "BBFF-" // Put here your Ubidots TOKEN
#endif
Ubidots ubidots(TOKEN, UBI_TCP); //Non Education
char data[200];
//setup() runs once
void setup(){
Serial.begin(115200);
pinMode(interruptPin, INPUT_PULLUP); //set pin mode with pullup
attachInterrupt(interruptPin, HallPulse, FALLING); //attach interrupt
Serial.println("Hall Effect RPM Test");
//setup output pins for pumping stations
pinMode(PUMP_IN_PIN, OUTPUT);
pinMode(PUMP_OUT_PIN, OUTPUT);
//setup input pins for buttons
pinMode(BUTTON_1_PIN, INPUT);
pinMode(BUTTON_2_PIN, INPUT);
}
//loop() runs indefinitely
void loop(){
//check pushbutton on pin BUTTON_1_PIN to see if it is HIGH (it has been pressed)
if(digitalRead(BUTTON_1_PIN) == HIGH)
{
digitalWrite(PUMP_IN_PIN, HIGH); //turn pump 1 on
delay(PUMP_IN_TIME); //wait PUMP_1_TIME milliseconds
digitalWrite(PUMP_IN_PIN, LOW); //turn pump 1 off
}
//check pushbutton on pin BUTTON_2_PIN to see if it is HIGH (it has been pressed)
if(digitalRead(BUTTON_2_PIN) == HIGH)
{
digitalWrite(PUMP_OUT_PIN, HIGH); //turn pump 2 on
delay(PUMP_OUT_TIME); //wait PUMP_2_TIME milliseconds
digitalWrite(PUMP_OUT_PIN, LOW); //turn pump 2 off
}
rpm = pulsecount*2;
snprintf(data, sizeof(data)-1, "%0.d%",rpm);
Particle.publish("rpm", data, PRIVATE);
ubidots.add("rpm", rpm);
//ubidots.send();
pulsecount = 0;
}
void HallPulse(){
noInterrupts();
halltime = millis(); // get current time
hallinterval = halltime - halllast; // calc time since last pulse
if (hallinterval > 50) // ignore switch-bounce glitches less than 50 ms
{
pulsecount++; // increment counter, sum # of tips
halllast = halltime; // set up for next event
}
interrupts();
}