So a while back I started with the original core from kickstarter. With the help of a nice gentleman on this forum I was able to get programming down for my project (with a simple website), which is a four channel peristaltic dosing pump.
Currently I can set each pump to run for a set period of time at an exact time. I would be curious about changing that programming so that I could put in a set amount of milliliters (knowing how many mL/hr) and it would be divided out to 12 doses over a 24hr period.
I’m also no opposed to purchasing a new Photon if that makes more sense.
Here is the original programming:
// This #include statement was automatically added by the Spark IDE.
#include "SparkTime.h"
UDP UDPClient;
SparkTime rtc;
int relayPin[4] = {D0,D1,D2,D3};
//By relays number
bool isSet[4] = {false,false,false,false};
uint8_t startHours[4] = {0,0,0,0};
uint8_t startMinutes[4] = {0,0,0,0};
uint8_t startSeconds[4] = {0,0,0,0};
unsigned int duration[4] = {0,0,0,0};
unsigned long stopTime[4] = {0,0,0,0};
#define NCHARS 32
char relayStr[4][NCHARS];
void setup()
{
for(int relay=0;relay<4;relay++) {
pinMode(relayPin[relay], OUTPUT);
digitalWrite(relayPin[relay], LOW);
}
Spark.function("setRelay1", setRelay1);
Spark.function("setRelay2", setRelay2);
Spark.function("setRelay3", setRelay3);
Spark.function("setRelay4", setRelay4);
Spark.variable("getRelay1", relayStr[0], STRING);
Spark.variable("getRelay2", relayStr[1], STRING);
Spark.variable("getRelay3", relayStr[2], STRING);
Spark.variable("getRelay4", relayStr[3], STRING);
rtc.begin(&UDPClient, "pool.ntp.org");
rtc.setTimeZone(-5); // gmt offset
rtc.setUseDST(true);
}
void loop() {
unsigned long currentTime = rtc.now();
for(int relay=0;relay<4;relay++) {
if (TRUE==isSet[relay]) {
if (rtc.hour(currentTime)==startHours[relay] &&
rtc.minute(currentTime)==startMinutes[relay] &&
rtc.second(currentTime)==startSeconds[relay]) {
digitalWrite(relayPin[relay],HIGH);
stopTime[relay] = currentTime + duration[relay];
} // start time
} // is set
if (currentTime >= stopTime[relay]) {
digitalWrite(relayPin[relay],LOW);
}
}
delay(100);
}
// Parse the format: 08:56:05*6000 or 18:59:00*10
// hh:mm:ss*duration
int parseTimeDuration(String command, int relay) {
char copyStr[33];
command.toCharArray(copyStr,33);
char *p = strtok(copyStr, ":");
startHours[relay] = (uint8_t)atoi(p);
p = strtok(NULL,":");
startMinutes[relay] = (uint8_t)atoi(p);
p = strtok(NULL,":");
startSeconds[relay] = (uint8_t)atoi(p);
p += 3;
duration[relay] = atoi(p);
isSet[relay] = true;
sprintf(relayStr[relay], "%02d:%02d:%02d*%d",startHours[relay],startMinutes[relay],startSeconds[relay],duration[relay]);
return 1;
}
int setRelay1(String command) {
return parseTimeDuration(command, 0);
}
int setRelay2(String command) {
return parseTimeDuration(command, 1);
}
int setRelay3(String command) {
return parseTimeDuration(command, 2);
}
int setRelay4(String command) {
return parseTimeDuration(command, 3);
}