Development

Sensors / Accelerometer:

» Acc 07: 6D position

This example shows how to manage the 6D Position recognition interruption

Required Materials

1 x Waspmote PRO
1 x MiniUSB wire

Notes

When the 6D position interrupt is activated, a change in position of Waspmote will generate an interruption and wake up Waspmote PRO.

Code

/*
 *  ------ [ACC_7] Waspmote Accelerometer 6D Position Example--------
 *
 *  Explanation: This example shows how to manage the 6D Position
 *  recognition interruption
 *
 *  Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Marcos Yarza
 */

long previous = 0;

void setup()
{
  ACC.ON();
  USB.ON(); // starts using the serial port
  USB.println(F("ACC_07 example"));
}


void loop()
{
  ACC.ON();
  USB.println(F("Accelerometer ON"));
  ACC.set6DPosition();
  USB.println("6D Position Recognition interrupt configured");
  
  USB.println("Go to sleep and wait 6D Position Recognition interrupt");
  PWR.sleep(ALL_OFF);
   
  if( intFlag & ACC_INT )
  {
    // clear the accelerometer interrupt flag on the general interrupt vector
    intFlag &= ~(ACC_INT);
    // read the acceleration source register
    delay(1000);
    USB.ON();
    USB.println(F("++++++++++++++++++++++++++++++++++++++++++++++++"));
    USB.println(F("++ 6D Position Recognition interrupt detected ++"));
    //USB.print(F("\r\n INT1_SRC: "));
    int aux = ACC.readRegister(INT1_SRC);
    //USB.println(aux,DEC);
    USB.print("++ Position: ");
    if (aux == 96) USB.print("+Z");
    if (aux == 80) USB.print("-Z");
    if (aux == 68) USB.print("+Y");
    if (aux == 72) USB.print("-Y");
    if (aux == 65) USB.print("+X");
    if (aux == 66) USB.print("-X");
    USB.println(F("                               ++"));
    USB.println(F("++++++++++++++++++++++++++++++++++++++++++++++++"));
    USB.println();
    
  }
  delay(500);
}

Output

B#
ACC_07 example
Accelerometer ON
6D Position Recognition interrupt configured
Go to sleep and wait 6D Position Recognition interrupt
++++++++++++++++++++++++++++++++++++++++++++++++
++ 6D Position Recognition interrupt detected ++
++ Position: +Z ++
++++++++++++++++++++++++++++++++++++++++++++++++

Accelerometer ON
6D Position Recognition interrupt configured
Go to sleep and wait 6D Position Recognition interrupt
++++++++++++++++++++++++++++++++++++++++++++++++
++ 6D Position Recognition interrupt detected ++
++ Position: +X ++
++++++++++++++++++++++++++++++++++++++++++++++++

Accelerometer ON
6D Position Recognition interrupt configured
Go to sleep and wait 6D Position Recognition interrupt
++++++++++++++++++++++++++++++++++++++++++++++++
++ 6D Position Recognition interrupt detected ++
++ Position: +Z ++
++++++++++++++++++++++++++++++++++++++++++++++++

Accelerometer ON
6D Position Recognition interrupt configured
Go to sleep and wait 6D Position Recognition interrupt
++++++++++++++++++++++++++++++++++++++++++++++++
++ 6D Position Recognition interrupt detected ++
++ Position: +X ++
++++++++++++++++++++++++++++++++++++++++++++++++

Accelerometer ON
6D Position Recognition interrupt configured
Go to sleep and wait 6D Position Recognition interrupt
++++++++++++++++++++++++++++++++++++++++++++++++
++ 6D Position Recognition interrupt detected ++
++ Position: -Y ++
++++++++++++++++++++++++++++++++++++++++++++++++

Quick Publish: