Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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);
- }
- }
- }
Add Comment
Please, Sign In to add comment