2023-08-01 23:38:12 +02:00
|
|
|
|
2023-08-02 01:04:39 +02:00
|
|
|
#include "ArduinoJson.h"
|
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
int analogPin = 3;
|
|
|
|
int data = 0;
|
|
|
|
char userInput;
|
|
|
|
|
2023-08-02 01:04:39 +02:00
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
void setup() {
|
|
|
|
// put your setup code here, to run once:
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
2023-08-02 01:04:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-01 23:38:12 +02:00
|
|
|
Serial.begin(9600);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
|
2023-08-02 01:04:39 +02:00
|
|
|
if(Serial.available()>0) {
|
|
|
|
|
|
|
|
//userInput = Serial.read();
|
|
|
|
|
|
|
|
// String input;
|
|
|
|
|
|
|
|
StaticJsonDocument<96> doc;
|
|
|
|
// { "command": "switch", "arg": "one", "state": "off"}
|
|
|
|
DeserializationError error = deserializeJson(doc, Serial);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
Serial.print(F("deserializeJson() failed: "));
|
|
|
|
Serial.println(error.f_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* command = doc["command"]; // "switch"
|
|
|
|
const char* arg = doc["arg"]; // "one"
|
|
|
|
const char* state = doc["state"]; // "off"
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print(command);
|
|
|
|
Serial.print(" - ");
|
|
|
|
Serial.print(arg);
|
|
|
|
Serial.print(" - ");
|
|
|
|
Serial.println(state);
|
2023-08-01 23:38:12 +02:00
|
|
|
|
|
|
|
if(userInput == 'g') {
|
|
|
|
|
|
|
|
data = analogRead(analogPin);
|
|
|
|
/*
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
|
|
delay(200); // wait for a second
|
|
|
|
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
|
|
|
delay(200);
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
|
|
delay(200); // wait for a second
|
|
|
|
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
|
|
|
delay(200);
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
|
|
delay(200); // wait for a second
|
|
|
|
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
|
|
|
delay(200);
|
|
|
|
|
|
|
|
*/
|
2023-08-02 01:04:39 +02:00
|
|
|
//delay(2000);
|
2023-08-01 23:38:12 +02:00
|
|
|
Serial.println(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|