Engduino Lights and Accelerometer Tutorial
This tutorial will combine both your knowledge of using the LEDs and the Accelerometer.
Repeat all of the steps on the first page of "Engduino Lights Tutorial - Basics".
You should end up looking at a blank loop action like this:
We will create a shake sensor, with the LEDs giving feedback to whether the Engduino is being
shaken or not. Let's start by storing the x, y and z values given from the accelerometer. Enter the
following line:
This stores your x value into a variable called "x". Now do the same for y and z. Try to do it yourself!
Store them in variables called "y" and "z". If you need help, look at the bottom of the page.
Now you want to total these values, with the following:
You may be wondering, what does "abs" do? Say your accelerometer value is negative. It will turn it
into a positive number. So if your x value was -1, it will be changed to 1. Consequently, if it was 1, it
would still be 1. This means we can total the 3 values all into one "total" variable more easily.
Now we'll finally use an if statement to set the LEDs to green if the LED is not being shaken, or red if
it is being shaken. For this, you want to enter the following code:
And that's it! Well done, you've created a shake sensor! Below is what your code should look like: