Skip to content

Instantly share code, notes, and snippets.

@adorsk
Last active September 25, 2019 01:40
Show Gist options
  • Save adorsk/58ebb36656d2b42fe2f91648ad902525 to your computer and use it in GitHub Desktop.
Save adorsk/58ebb36656d2b42fe2f91648ad902525 to your computer and use it in GitHub Desktop.
DrippyTron Arduino
int counter = 0;
int signalPin = 3;
int feeding = 1;
int msPerPulse = 100;
int msPerPulseInterval = 500;
// Feed time (affects how much material to feed)
int numPulses = 25;
int delayPerPulse = 100;
int initializing = 1;
int initialDelay = 5 * 1000;
//int delayPerPulse = 100;
void setup() {
pinMode(signalPin, OUTPUT);
Serial.begin(9600);
Serial.print("Starting!");
}
void loop() {
if (initializing == 1) {
delay(initialDelay);
initializing = 0;
}
delay(delayPerPulse);
if (feeding == 1) {
digitalWrite(signalPin, HIGH);
delay(msPerPulse);
digitalWrite(signalPin, LOW);
delay(msPerPulseInterval);
counter += 1;
if (counter > numPulses) {
feeding = 0;
}
}
}
int counter = 0;
int signalPin = 3;
int feeding = 1;
// pulse parameters (affects feed rate)
int msPerPulse = 200;
int msPerPulseInterval = 100;
// Feed time (affects how much material to feed)
int msPerFeed = round(8.5 * 1000);
int msBetweenFeeds = 5 * 60 * 1000;
unsigned long feedStartTime;
unsigned long feedEndTime;
unsigned long curTime;
void setup() {
pinMode(signalPin, OUTPUT);
feedStartTime = millis();
Serial.begin(9600);
Serial.print("Starting!");
}
void loop() {
curTime = millis();
if (feeding == 1) {
digitalWrite(signalPin, HIGH);
delay(msPerPulse);
digitalWrite(signalPin, LOW);
delay(msPerPulseInterval);
if ((curTime - feedStartTime) > msPerFeed) {
feedEndTime = curTime;
feeding = 0;
}
} else if (feeding == 0) {
if ((curTime - feedEndTime) > msBetweenFeeds) {
feeding = 1;
feedStartTime = curTime;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment