Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- SoftwareSerial HM10(2, 3); // RX = 2, TX = 3
- char appData;
- String inData="";
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- Serial.println("HM10 serial started at 9600");
- HM10.begin(9600);
- pinMode(12, OUTPUT);
- digitalWrite(12, HIGH);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- HM10.listen(); // czyta najpierw port zanim HM10 bedzie dostępne i wyśle dane. Zapisuje dane w stringu
- while (HM10.available() > 0){ // jeśli HM coś wyśłe i odczyta
- appData = HM10.read();
- inData = String(appData); //zapisuje dane w formacie string
- Serial.write(appData);
- }
- if (Serial.available()){ // debugowanie HM10 przez komende AT. Wysyła string do HM10
- delay(10);
- HM10.write(Serial.read());
- }
- if ( inData == "c") {
- Serial.println("Door close");
- digitalWrite(12, HIGH); // switch OFF LED
- delay(500);
- digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(1000); // wait for a second
- // wait for a second
- }
- if ( inData == "o") {
- Serial.println("Door open");
- digitalWrite(12, LOW); // switch OFF LED
- delay(500);
- digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
- delay(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement