Created
November 18, 2017 01:38
-
-
Save pipoblak/dc85bbd7c79fe5afd0946c6277dcad82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Projeto Flutuador | |
*/ | |
#include "SoftwareSerial.h" | |
SoftwareSerial bluetooth(2, 3); //TX, RX (Bluetooth) | |
const int pumpPin = 13; // the pin that the LED is attached to | |
int incomingByte; // a variable to read incoming serial data into | |
boolean currentState=false; | |
int lastTime=0; | |
int nextTime=0; | |
void setup() { | |
//Initialize the software serial | |
bluetooth.begin(9600); | |
// initialize the LED pin as an output: | |
pinMode(pumpPin, OUTPUT); | |
} | |
void loop() { | |
lastTime=millis(); | |
if(nextTime<lastTime){ | |
nextTime= millis() + 5000; | |
unsigned long allSeconds=millis()/1000; | |
int runHours= allSeconds/3600; | |
int secsRemaining=allSeconds%3600; | |
int runMinutes=secsRemaining/60; | |
int runSeconds=secsRemaining%60; | |
char buf[21]; | |
sprintf(buf,"%02d:%02d:%02d",runHours,runMinutes,runSeconds); | |
bluetooth.println(buf); | |
} | |
// see if there's incoming serial data: | |
if (bluetooth.available() > 0) { | |
// read the oldest byte in the serial buffer: | |
incomingByte = bluetooth.read(); | |
// if it's a capital H (ASCII 72), turn on the PUMP: | |
if (incomingByte == '!') { | |
currentState=!currentState; | |
if(currentState) | |
digitalWrite(pumpPin, HIGH); | |
else | |
digitalWrite(pumpPin, LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment