arduino-fridge-powercontrol/main/main.ino
2023-08-02 01:04:39 +02:00

72 lines
1.8 KiB
C++

#include "ArduinoJson.h"
int analogPin = 3;
int data = 0;
char userInput;
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
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);
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);
*/
//delay(2000);
Serial.println(data);
}
}
}