Advertisement
RuiViana

Le multiplo String

Sep 27th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. SoftwareSerial bt(1 , 2); // TX RX
  4. String str ;
  5. String inString = "";
  6. int portao = 3; // a
  7. int rele1 = 4; // b
  8.  
  9.  
  10. void setup() {
  11. bt.begin(9600);
  12. pinMode(portao, OUTPUT); // a
  13. bt.begin(9600);
  14. pinMode(rele1, OUTPUT); // b
  15. bt.begin(9600);
  16.  
  17. }
  18.  
  19. void loop() {
  20. if (bt.available()>0)
  21. {
  22. str = bt.readStringUntil('\n');
  23. inString = inString + str;
  24.  
  25. if (inString == "aa") {
  26. digitalWrite(portao, HIGH); // a
  27. bt.println("OK, port A/F.");
  28. }
  29. if (inString == "AA") {
  30. digitalWrite(portao, LOW);
  31. bt.println("OK, port a/f.");
  32. }
  33. if (inString == "bb") {
  34. digitalWrite(rele1, HIGH);
  35. bt.println("OK, rele1 ligad."); // b
  36. }
  37. if (inString == "BB") {
  38. digitalWrite(rele1, LOW);
  39. bt.println("OK, rele1 deslig.");
  40.  
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement