Guest User

Untitled

a guest
Nov 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. Projeto Flutuador
  3. */
  4.  
  5. #include "SoftwareSerial.h"
  6.  
  7. SoftwareSerial bluetooth(2, 3); //TX, RX (Bluetooth)
  8.  
  9. const int pumpPin = 13; // the pin that the LED is attached to
  10. int incomingByte; // a variable to read incoming serial data into
  11. boolean currentState=false;
  12. int lastTime=0;
  13. int nextTime=0;
  14. void setup() {
  15. //Initialize the software serial
  16. bluetooth.begin(9600);
  17.  
  18. // initialize the LED pin as an output:
  19. pinMode(pumpPin, OUTPUT);
  20. }
  21.  
  22. void loop() {
  23. lastTime=millis();
  24. if(nextTime<lastTime){
  25. nextTime= millis() + 5000;
  26. unsigned long allSeconds=millis()/1000;
  27. int runHours= allSeconds/3600;
  28. int secsRemaining=allSeconds%3600;
  29. int runMinutes=secsRemaining/60;
  30. int runSeconds=secsRemaining%60;
  31.  
  32. char buf[21];
  33. sprintf(buf,"%02d:%02d:%02d",runHours,runMinutes,runSeconds);
  34. bluetooth.println(buf);
  35. }
  36. // see if there's incoming serial data:
  37.  
  38. if (bluetooth.available() > 0) {
  39. // read the oldest byte in the serial buffer:
  40. incomingByte = bluetooth.read();
  41. // if it's a capital H (ASCII 72), turn on the PUMP:
  42. if (incomingByte == '!') {
  43. currentState=!currentState;
  44. if(currentState)
  45. digitalWrite(pumpPin, HIGH);
  46. else
  47. digitalWrite(pumpPin, LOW);
  48. }
  49.  
  50. }
  51. }
Add Comment
Please, Sign In to add comment