/*
Author: Will Forfang
Corresponding Email: W.Forfang@gmail.com
Date: 6/4/2013
This program samples an analog voltage signal (sensor output) and stores the last N samples in a buffer.
It computes the average of samples in the buffer, converts the average to an array of characters, and then
transmit the array via RF to a receiver.
*/
// Global area
#include <VirtualWire.h> //Make sure this library is installed in your 'Energia\hardware\msp430\libraries' directory.
const int transmit_pin = 9; //pin 9 on launchpad is P2_1
const int receive_pin = 2; //P1_0
const int transmit_en_pin = 3; //P1_1
const int xpin = 5; // output of accel, or temp sensor goes to analog input 3 (P1_3) on launchpad
const int frameLength = 120; //number of samples with which to calculate statistics
int frame [frameLength]; //initialize
float sum = 0; //initialize
char avgChar[7]; //initialize
void setup(){
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
Serial.begin( 9600 ); }
void loop(){
Serial.println("test"); //for debugging
sum = 0;
byte count = 0;
for (count = 0; count<frameLength; count++)
{
int currentValue = analogRead(xpin);
frame[count] = analogRead(xpin); //frame of samples; not used yet
sum = sum + currentValue;
}
//compute average of time-domain samples in 'frame'
int avg = sum / frameLength;
//Convert integer to char array for transmission
itoa(avg,avgChar,7);
// vw_send((uint8_t*)avgChar, 7);
vw_send((uint8_t *)avgChar, strlen(avgChar));
vw_wait_tx(); // Wait until the whole message is gone
Serial.print("temp:");
Serial.print("\t"); //tab
Serial.print(avgChar);
Serial.print("\n"); //new line
}