Updated maple hardware code for faster ping, better code.

This commit is contained in:
Philip Rosedale 2013-01-30 15:28:43 -08:00
parent 6ce7f1890d
commit 3469ecef21
2 changed files with 30 additions and 23 deletions

View file

@ -1,23 +1,26 @@
/*
Read a set of analog input lines and echo their readings over the serial port with averaging
*/
// ADC PIN MAPPINGS
//
// 15,16 = Head Pitch, Yaw gyro
// 17,18,19 = Head Accelerometer
// Read Gyro and accelerometer data, send over serialUSB to computer for processing.
//
// Written by Philip, 2012, for High Fidelity, Inc.
//
// PIN WIRING: Connect input sensors to the channels in following manner
//
// AIN 15: Pitch Gyro (nodding your head 'yes')
// AIN 16: Yaw Gyro (shaking your head 'no')
// AIN 17: Roll Gyro (looking quizzical, tilting your head)
// AIN 18: Lateral acceleration (moving from side-to-side in front of your monitor)
// AIN 19: Up/Down acceleration (sitting up/ducking in front of your monitor)
// AIN 20: Forward/Back acceleration (Toward or away from your monitor)
#define NUM_CHANNELS 6
#define MSECS_PER_SAMPLE 15
#define MSECS_PER_SAMPLE 10
#define LED_PIN 12
int inputPins[NUM_CHANNELS] = {19,20,18,15,16,17};
int LED_on = 0;
unsigned int total_count = 0;
int inputPins[NUM_CHANNELS] = {15,16,17,18,19,20};
int LED = 0;
unsigned int samplesSent = 0;
unsigned int time;
int measured[NUM_CHANNELS];
@ -42,30 +45,34 @@ void loop()
{
int i;
sampleCount++;
total_count++;
if (total_count % 20172 == 0) {
LED_on = !LED_on;
if (LED_on) digitalWrite(LED_PIN, HIGH);
else digitalWrite(LED_PIN, LOW);
}
for (i = 0; i < NUM_CHANNELS; i++) {
accumulate[i] += analogRead(inputPins[i]);
}
if ((millis() - time) >= MSECS_PER_SAMPLE) {
samplesSent++;
time = millis();
for (i = 0; i < NUM_CHANNELS; i++) {
measured[i] = accumulate[i] / sampleCount;
SerialUSB.print(measured[i]);
SerialUSB.print(" ");
accumulate[i] = 0;
}
}
if ((samplesSent % 100 == 0) && (samplesSent % 150 == 0)) {
LED = !LED;
digitalWrite(LED_PIN, LED);
digitalWrite(BOARD_LED_PIN, LED);
}
SerialUSB.print(sampleCount);
SerialUSB.print(" ");
if (LED_on) SerialUSB.print("1");
else SerialUSB.print("0");
if (LED)
SerialUSB.print("1");
else
SerialUSB.print("0");
SerialUSB.println("");
sampleCount = 0;
}
}