09.04.2016 Views

www.ebook777.com

Make_Getting_Started_with_Processing_Second_Edition

Make_Getting_Started_with_Processing_Second_Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

198 Getting Started with Processing<br />

<strong>www</strong>.<strong>ebook777.com</strong><br />

}<br />

if (x > width) {<br />

x = 0;<br />

}<br />

Similar to Example 5-8 on page 54 and Example 5-9 on page 55,<br />

this sketch uses the easing technique. Each new byte from the<br />

Arduino board is set as the target value, the difference between<br />

the current value and the target value is calculated, and the current<br />

value is moved closer to the target. Adjust the easing variable<br />

to affect the amount of smoothing applied to the incoming<br />

values.<br />

Example 13-9: Another Way to Look<br />

at the Data<br />

This example is inspired by radar display screens. The values<br />

are read in the same way from the Arduino board, but they are<br />

visualized in a circular pattern using the sin() and cos() functions<br />

introduced earlier in Example 8-12 on page 115, Example<br />

8-13 on page 115, and Example 8-15 on page 116:<br />

import processing.serial.*;<br />

Serial port; // Create object from Serial class<br />

float val; // Data received from the serial port<br />

float angle;<br />

float radius;<br />

void setup() {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!