From 6f553ed23cc790e6ddb4e499919076689babe670 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 9 Nov 2017 09:45:16 +0100 Subject: [PATCH] Add examples --- source/_components/sensor.serial.markdown | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/source/_components/sensor.serial.markdown b/source/_components/sensor.serial.markdown index c66fe9386ad..52646cf648a 100644 --- a/source/_components/sensor.serial.markdown +++ b/source/_components/sensor.serial.markdown @@ -57,4 +57,35 @@ sensor: ``` {% endraw %} +## {% linkable_title Examples %} +### {% linkable_title Arduino %} + +For controllers of the Arduino family a possible sketch to read the temperature and the humidity could look like the sample below. + +``` +#include + +void setup() { + Serial.begin(115200); +} + +void loop() { + StaticJsonBuffer<100> jsonBuffer; + JsonObject& json = prepareResponse(jsonBuffer); + json.printTo(Serial); + Serial.println(); + delay(2000); +} + +JsonObject& prepareResponse(JsonBuffer& jsonBuffer) { + JsonObject& root = jsonBuffer.createObject(); + root["temperature"] = analogRead(A0); + root["humidity"] = analogRead(A1); + return root; +} +``` + +### {% linkable_title Digispark USB Development Board %} + +This [blog post](/blog/2017/10/23/simple-analog-sensor/) describes the setup with a Digispark USB Development Board.