More Related Content
Similar to Michael kontopoulos
Similar to Michael kontopoulos (20)
More from josnihmurni2907
More from josnihmurni2907 (20)
Michael kontopoulos
- 1. /*
Michael Kontopoulos
2009
Sigh Collector (Reciever Module)
*/
#include <NewSoftSerial.h>
NewSoftSerial mySerial = NewSoftSerial(2,3); //instead of 1,2 (rx,tx)
int ledPin = 13;
int pump = 9;
int reading;
int previous = LOW;
long time = 0; // the last time the output pin was toggled
long debounce = 1000; // the debounce time, increase if the output
flickers
boolean pumpRunning;
int stepCounter;
long pumpStartTime=0;
long thresh;
void setup()
{
pinMode(pump, OUTPUT);
pumpRunning = false;
stepCounter = 0;
thresh = 2000;
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
serialHandler();
char val = (char)mySerial.read();
if(val == '8') //red button
{
reading = HIGH;
Serial.print("sigh! stationary unitt");
//Serial.print(reading);
}
else{
reading = LOW;
}
//Pump check
if(!pumpRunning && stepCounter > 0)
{
startPump();
stepCounter--;
}
long diff = millis() - pumpStartTime;
if (pumpRunning && diff > thresh)
- 2. {
stopPump();
}
//Register button pressing
//Includes Debouncing
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
stepCounter++;
time = millis();
}
previous = reading;
} // end main
void startPump()
{
digitalWrite(ledPin, HIGH);
digitalWrite(pump, HIGH);
pumpRunning = true;
pumpStartTime = millis();
}
void stopPump()
{
digitalWrite(ledPin, LOW);
digitalWrite(pump, LOW);
pumpRunning = false;
}
void serialHandler()
{
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
delay(100);
}