The Tactigon Accelerometer and LEDs Interaction

by The Tactigon in Circuits > Arduino

424 Views, 0 Favorites, 0 Comments

The Tactigon Accelerometer and LEDs Interaction

Gesture Sample Project Step#1

This article will explain how to use The Tactigon’s integrated sensors and communication interfaces to create a simple gesture controller.

Source code is available here on GitHub

In this first article we’re going to learn how to use simple functions of The Tactigon to light up the integrated LEDs intercepting data from internal accelerometer.

  • Used Libraries
  • Loop()
  • Final considerations

Used Libraries

sketch-ridotto.gif

This example uses few essential libraries:

  • tactigon_led.h
  • tactigon_IMU.h
  • IMU_main.h

tactigon_led.h

This library is dedicated to integrated LEDs.

It exposes T_Led type, which instances are declared:

T_Led rLed, bLed, gLed;

In the void setup() function, LEDs are initialized using static fields offered by T_Led:

rLed.init(T_Led::RED);

gLed.init(T_Led::GREEN);

bLed.init(T_Led::BLUE);

LEDs are suddenly turned off with simple method offered by T_Led class:

rLed.off();

gLed.off();

bLed.off();

T_Led class offers also a method to light on the LEDs:

rLed.on();

gLed.on();

bLed.on();

tactigon_IMU.h

This library, provides few classes usefull when data from integrated IMU is needed. In this article we’ll look at T_ACC and T_AccData.
In this sketch, we declared:

T_ACC accMeter;

T_AccData accData;

By having a T_ACC object we can ask him for the 3 axis data:

The method:

accMeter.getAxis();

returns a T_AccData object containing the last three measured accelerations in each axis.

T_AccData type has three fields, accData.x, accData.y, accData.z. Each one of this fields contains acceleration value in milliG.

To refresh data we have to analyse the next library.

IMU_main.h

This library is used in this sketch to be able to use IMU_loop() function.
This function is called each void loop() iteration to refresh IMU data.

Loop()

loop() function in this sketch will first of all refresh IMU values by calling IMU_loop() function.

Now that we have updated values from the sensors, we can use them to determine if an acceleration is greater than 500 milliG and light up the LED color related to that axis.

As we learned in the tactigon_IMU.h paragraph, by calling accMeter.getAxis() we get the X,Y and Z acceleration values gathered in this loop iteration.

We can so use the accData.x, accData.y, accData.z fields to compare this value with our threshold of 500millig. Since we don’t care about orientation but only direction, we use abs() function to get absolute value of this acceleration.

X AXIS (SAME APPLIES TO Y AND Z):

if(abs(accData.x) > 500)

rLed.on();

else

rLed.off();

Final Considerations

retro presentazione.jpg

This simple sketch is only the first step towards a Gesture Controller with The Tactigon. In next articles we’ll learn how to use other integrated devices as Bluetooth Low Energy, Gyroscope, Magnetometer, Temperature Sensor and Pressure Sensor, and communicate with Android Application created in Processing.

Stay tuned for more Tactigon’s code!