takes acceleration values from accelerometer, compares them with some threshold values and send keywords serially

Dependencies:   mbed

main.cpp

Committer:
tusharkarwa001
Date:
2013-10-29
Revision:
0:e0bd8c53c503

File content as of revision 0:e0bd8c53c503:

//Program to transmit data from master to slave

#include "mbed.h"
#include "AnalogIn.h"
#include "Serial.h"

AnalogIn x(p15),y(p16);     //create an AnalogIn for accelerometer
Serial master(p9,NC);       //create a serial port to transmit data to the receiver

int main() 
{
float X1,Y1;                //variables to store acceleration values in X and Y
master.baud(19200);         //set baud rate to 19200 
while(1)
{
    X1=x.read();            //read acceleration values in x direction
    Y1=y.read();            //read acceleration values  in y direction
          
    if(X1>0.55)             // comparison with threshold values  for positive X
    master.printf("a\0");   // send a specified token(command)
    else if(X1<0.47)        // comparison with threshold values  for negative X
    master.printf("d\0");   
    if(Y1>0.55)             // comparison with threshold values  for negative Y
    master.printf("s\0");   
    else if(Y1<0.47)        // comparison with threshold values  for positive Y
    master.printf("w\0");   
    wait(0.1);
    }
  
}