GY-63_MS5611/libraries/XMLWriter/examples/XMLWriterTest/XMLWriterTest.ino

135 lines
2.8 KiB
Arduino
Raw Normal View History

//
// FILE: XMLWriterTest.ino
// AUTHOR: Rob Tillaart
// PURPOSE: make a simple XML generating lib
// DATE: 2013-11-06
2020-05-25 03:58:04 -04:00
// URL: https://github.com/RobTillaart/XMLWriter
2021-12-29 10:27:03 -05:00
#include <XMLWriter.h>
XMLWriter XML(&Serial);
char buffer[24];
2021-11-11 14:36:58 -05:00
void setup()
{
Serial.begin(115200);
2020-05-25 03:58:04 -04:00
uint32_t start = micros();
XML.setConfig(0); // comment this line to see difference
XML.header();
XML.comment("XMLWriterTest.ino\nThis is a demo of a simple XML lib for Arduino", true);
2020-05-25 03:58:04 -04:00
// XML.newLine(0);
XML.tagOpen("Arduino", "42");
XML.tagOpen("Ports");
AnalogPorts("before");
DigitalPorts();
AnalogPorts("after");
XML.tagClose();
Weather();
Weather2();
DataTypes();
XML.tagClose();
2021-11-11 14:36:58 -05:00
XML.flush();
2020-05-25 03:58:04 -04:00
uint32_t stop = micros();
Serial.println(stop - start);
Serial.println("done...");
}
2021-11-11 14:36:58 -05:00
void Weather2()
{
XML.comment("The weather in South Africa");
2020-05-25 03:58:04 -04:00
for (int i = 0; i < 10; i++)
{
XML.tagStart("Weather");
XML.tagField("Date", "20131106");
XML.tagField("Time", "1:42");
XML.tagField("Temp", "23.4");
XML.tagField("Humi", "50%");
XML.tagField("Rain", "10mm");
XML.tagField("Sun", "40");
XML.tagEnd();
}
}
2021-11-11 14:36:58 -05:00
void Weather()
{
XML.comment("The weather in Nebraska");
XML.tagOpen("Weather");
XML.writeNode("Date", "20131106");
XML.writeNode("Time", "11:42");
XML.writeNode("Temp", "23.4");
XML.writeNode("Humi", "50%");
XML.writeNode("Rain", "10mm");
XML.writeNode("Sun", "40");
XML.tagClose();
}
2021-11-11 14:36:58 -05:00
2021-01-29 06:31:58 -05:00
// casting to keep some compilers happy
void AnalogPorts(const char* name)
{
XML.comment("The analog ports are multiplexed");
XML.tagOpen("Analog", name);
XML.writeNode("Analog0", itoa(analogRead(A0), buffer, 10));
2021-01-29 06:31:58 -05:00
XML.writeNode("Analog1", (uint16_t) analogRead(A1));
XML.writeNode("Analog2", (double) (5.0*analogRead(A2))/1023); // default nr decimals = 2
XML.writeNode("Analog3", (double) (5.0*analogRead(A2))/1023, (uint8_t)3);
XML.tagClose();
}
2021-11-11 14:36:58 -05:00
void DigitalPorts()
{
XML.comment("The digital ports are not multiplexed");
XML.tagOpen("Digital");
XML.writeNode("D1", itoa(digitalRead(1), buffer, 10));
2021-01-29 06:31:58 -05:00
XML.writeNode("D13", (uint8_t)digitalRead(13));
XML.tagClose();
}
2021-11-11 14:36:58 -05:00
void DataTypes()
{
XML.comment("Testing dataTypes I");
XML.tagOpen("Datatypes");
2020-05-25 03:58:04 -04:00
XML.writeNode("BoolT", 1 == 1);
XML.writeNode("BoolF", 1 == 0);
XML.writeNode("BIN", 42, BIN);
XML.writeNode("DEC", 42, DEC);
XML.writeNode("HEX", 42, HEX);
XML.writeNode("OCT", 42, OCT);
XML.tagClose();
2020-05-25 03:58:04 -04:00
XML.comment("Testing dataTypes II");
2020-05-25 03:58:04 -04:00
for (int i = 0; i < 3; i++)
{
XML.tagStart("dataTypes");
2020-05-25 03:58:04 -04:00
XML.tagField("BoolT", 1 == 1);
XML.tagField("BoolF", 1 == 0);
int x = analogRead(A0);
XML.tagField("BIN", x, BIN);
XML.tagField("DEC", x, DEC);
XML.tagField("HEX", x, HEX);
XML.tagField("OCT", x, OCT);
XML.tagEnd();
}
}
2021-11-11 14:36:58 -05:00
void loop()
{
2020-05-25 03:58:04 -04:00
}
2021-11-11 14:36:58 -05:00
2020-05-25 03:58:04 -04:00
// -- END OF FILE --
2021-11-11 14:36:58 -05:00