Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial HM10(2, 3); // RX = 2, TX = 3
  3.  
  4. char appData;
  5. String inData="";
  6.  
  7.  
  8.  
  9.  
  10. void setup() {
  11. // put your setup code here, to run once:
  12. Serial.begin(9600);
  13. Serial.println("HM10 serial started at 9600");
  14. HM10.begin(9600);
  15. pinMode(12, OUTPUT);
  16. digitalWrite(12, HIGH);
  17.  
  18. }
  19.  
  20. void loop() {
  21. // put your main code here, to run repeatedly:
  22. HM10.listen(); // czyta najpierw port zanim HM10 bedzie dostępne i wyśle dane. Zapisuje dane w stringu
  23. while (HM10.available() > 0){ // jeśli HM coś wyśłe i odczyta
  24. appData = HM10.read();
  25. inData = String(appData); //zapisuje dane w formacie string
  26. Serial.write(appData);
  27. }
  28. if (Serial.available()){ // debugowanie HM10 przez komende AT. Wysyła string do HM10
  29. delay(10);
  30. HM10.write(Serial.read());
  31. }
  32. if ( inData == "c") {
  33. Serial.println("Door close");
  34. digitalWrite(12, HIGH); // switch OFF LED
  35. delay(500);
  36. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  37. delay(1000); // wait for a second
  38. // wait for a second
  39. }
  40. if ( inData == "o") {
  41. Serial.println("Door open");
  42. digitalWrite(12, LOW); // switch OFF LED
  43. delay(500);
  44. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  45. delay(1000);
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement