Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: update Accelerometer programs syntax #1603

Merged
merged 1 commit into from
Aug 21, 2019

Conversation

rwaldron
Copy link
Owner

No description provided.

console.log(" orientation : ", this.orientation);
console.log(" x : ", accelerometer.x);
console.log(" y : ", accelerometer.y);
console.log(" z : ", accelerometer.z);
Copy link
Collaborator

@dtex dtex Aug 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change events pass a single object {x, y, z} as a parameter. Could we illustrate that here with:

accelerometer.on("change", raw => {
    console.log(`  x            : ${raw.x}`);
    console.log(`  y            : ${raw.y}`);
    console.log(`  z            : ${raw.z}`);
    // And then switch to accessing properties on the instance
    console.log(`  pitch    : ${accelerometer.pitch}`);
    ... etc ...
});

?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of these baseline examples is to be able to see the consistent output across all instances, of all instance properties, regardless of controller/driver. If you want to make alternate versions of these, which looked like:

const {Accelerometer, Board} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", () => {
  const accelerometer = new Accelerometer({
    controller: "ADXL335",
    pins: ["A0", "A1", "A2"]
  });

  accelerometer.on("change", data => {
    console.log("accelerometer");
    console.log("  x            : ", data.x);
    console.log("  y            : ", data.y);
    console.log("  z            : ", data.z);
    console.log("--------------------------------------");
  });
});

...And are named accelerometer-adxl335-change-event-data.js and co-exist with the examples we currently have, then by all means!

@rwaldron rwaldron merged commit 247734c into master Aug 21, 2019
@rwaldron rwaldron deleted the accelerometer-examples branch April 2, 2020 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants