diff --git a/Source/hardware/head_hand/head_hand.pde b/Source/hardware/head_hand/head_hand.pde index 8618674cc3..6cec667fd6 100644 --- a/Source/hardware/head_hand/head_hand.pde +++ b/Source/hardware/head_hand/head_hand.pde @@ -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; } } diff --git a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate index 82a71f4e65..78474f027d 100644 Binary files a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate and b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate differ