Making Things Talk by Tom Igoe
Author:Tom Igoe
Language: eng
Format: mobi, epub
Tags: COMPUTERS / Hardware / General
Publisher: Make
Published: 2011-09-08T04:00:00+00:00
Next, add some code to add a time stamp. First, add a global variable to set the text line height.
int lineHeight = 14; // a variable to set the line height
Add a method to the end of the program, drawReadings(). This will display the date, time, voltage reading, and received signal strength.
Call this method from a few different places in the program; first, at the end of the setup() method:
// show the readings text: drawReadings(0,0);
Next, to draw the latest readings, call it at the end of the parseData() method:
// draw a line on the graph, // and the readings: drawGraph(average); drawReadings(average, signalStrength);
void drawReadings(int thisReading, int thisSignalStrength) { // set up an array to get the names of the months // from their numeric values: String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; // format the date string: String date = day() + " " + months[month() −1] + " " + year() ; // format the time string // all digits are number-formatted as two digits: String time = nf(hour(), 2) + ":" + nf(minute(), 2) + ":" + nf(second(), 2); // calculate the voltage from the reading: float voltage = thisReading * 3.3 / 1024; // choose a position for the text: int xPos = 20; int yPos = 20; // erase the previous readings: noStroke(); fill(0); rect(xPos,yPos, 180, 80); // change the fill color for the text: fill(#4F9FE1); // print the readings: text(date, xPos, yPos + lineHeight); text(time, xPos, yPos + (2 * lineHeight)); text("Voltage: " + voltage + "V", xPos, yPos + (3 * lineHeight)); text("Signal Strength: -" + thisSignalStrength + " dBm", xPos, yPos + (4 * lineHeight)); }
That’s the whole program. When it’s running, it should look like Figure 7-16.
Download
Making Things Talk by Tom Igoe.epub
Making Things Talk by Tom Igoe.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Linux Device Driver Development Cookbook by Rodolfo Giometti(3935)
Embedded Programming with Modern C++ Cookbook by Igor Viarheichyk(3625)
Implementing Cellular IoT Solutions for Digital Transformation by Dennis McCain(3559)
Embedded Linux Development Using Yocto Project - Third Edition by Otavio Salvador & Daiane Angolini(3394)
TinyML Cookbook by Gian Marco Iodice(3326)
Simplifying 3D Printing with OpenSCAD by Colin Dow(2843)
TinyML Cookbook by Gian Marco Iodice & Ronan Naughton(2604)
Fusion 360 for Makers by Lydia Sloan Cline(2221)
Networking A Beginner's Guide by Bruce Hallberg(2210)
Hands-On Linux for Architects by Denis Salamanca(2052)
But How Do It Know? by J. Clark Scott(2032)
Computers For Seniors For Dummies by Nancy C. Muir(2001)
Raspberry Pi and MQTT Essentials by Dhairya Parikh(1953)
Arduino Project Handbook, Volume 2: 25 Simple Electronics Projects for Beginners by Geddes Mark(1948)
9781803246888-ENHANCING DEEP LEARNING WITH BAYESIAN INFERENCE by Unknown(1902)
Hack and HHVM by Owen Yamauchi(1884)
31 Days Before Your CompTIA A+ Exams (Shanette Luellen's Library) by Benjamin Patrick Conry(1861)
MicroPython Projects by Jacob Beningo(1737)
Hands-On Internet of Things with MQTT by Tim Pulver(1709)
