Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MemoryFree.h>
- #include <EEPROM.h>
- #define PIN_LED 13 // вывод светодиода
- String inString;
- // Настройка
- void setup() {
- // Инициализация портов и выходов
- Serial.begin(115200);
- Serial3.begin(115200);
- pinMode(PIN_LED, OUTPUT);
- digitalWrite(PIN_LED, LOW);
- }
- // Выполнение
- void loop() {
- }
- // Проверка события на порту Serial3
- void serialEvent3() {
- while (Serial3.available()) {
- // Чтение данных из порта Serial3
- char inChar = Serial3.read();
- // Вывод прочитанных данных в порт Serial
- Serial.write(inChar);
- // Поиск команды в полученных данных (команда должна быть в квадратных скобках)
- inString += inChar;
- if (inChar == ']') {
- if (inString.indexOf("[ON]")>0) {
- digitalWrite(PIN_LED, HIGH);
- }
- else if (inString.indexOf("[OFF]")>0) {
- digitalWrite(PIN_LED, LOW);
- }
- else
- {
- Serial.println("Wrong command");
- }
- inString = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment