Skip to Content
Making Things Talk
book

Making Things Talk

by Tom Igoe
September 2007
Beginner to intermediate
432 pages
17h 48m
English
O'Reilly Media, Inc.
Content preview from Making Things Talk
256 MAKING THINGS TALK
Continued from previous page.
// read <numSamples> 10-bit analog values, two at a time
// because each reading is two bytes long:
for (int i = 0; i < numSamples * 2; i=i+2) {
// 10-bit value = high byte * 256 + low byte:
int thisSample = (thisPacket[i + adcStart] * 256) +
thisPacket[(i + 1) + adcStart];
// put the result in one of 5 bytes:
adcValues[i/2] = thisSample;
// add the result to the total for averaging later:
total = total + thisSample;
}
// average the result:
int average = total / numSamples;
print("Average reading:" + average + "\t");
// print the received signal strength:
println("Signal Strength:" + rssi);
}
Now that you’ve got the average
reading printing out, add some code to
graph the result. For this, you’ll need a
new global variable before the setup()
method that keeps track of where you
are horizontally on the graph:
8
int hPos = 0; // horizontal position on the graph
Now add a new method,
drawGraph(), to the end of the
program:
Call this from the parseData() method,
replacing the println() statement that
prints out the average, as well as the
println() statement that prints out the
signal strength (rssi), like so:
// draw a line on the graph:
drawGraph(average/4);
Now when you run the program, it
should draw a graph of the sensor
readings, updating every time it gets
a new datagram.
8
/*
upd
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Making Things Talk, 2nd Edition

Making Things Talk, 2nd Edition

Tom Igoe

Publisher Resources

ISBN: 9780596510510Catalog PageErrata