In the "open source head tracker" project, there is code for the Arduino.
Pin number 11 is apparently used to centre the headtracker.
Looking for where they define this pin 11 as button_input but I cannot see it.
I can see where they use it to set the pullup and I can see where they set it as an input and also where they get a value from it.
However, I cannot see where they assign button_input to pin 11.
Is it not required in this instance for some reason?
Note that I have only included a section of the code I believe in question as it would not allow the full code to be posted.
//-----------------------------------------------------------------------------
// Original project by Dennis Frie - 2012 - Dennis.frie@gmail.com
// Discussion: http://www.rcgroups.com/forums/showthread.php?t=1677559
//
// Other contributors to this code:
// Mark Mansur (Mangus on rcgroups)
//
// Version history:
// - 0.01 - 0.08 - Dennis Frie - preliminary releases
// - 1.01 - April 2013 - Mark Mansur - code clean-up and refactoring, comments
// added. Added pause functionality, added settings retrieval commands.
// Minor optimizations.
//-----------------------------------------------------------------------------
#include <Wire.h>
#include "config.h"
#include "functions.h"
#include "sensors.h"
#include <EEPROM.h>
/*
Channel mapping/config for PPM out:
1 = PPM CHANNEL 1
2 = PPM CHANNEL 2
3 = PPM CHANNEL 3
4 = PPM CHANNEL 4
5 = PPM CHANNEL 5
6 = PPM CHANNEL 6
7 = PPM CHANNEL 7
8 = PPM CHANNEL 8
9 = PPM CHANNEL 9
10 = PPM CHANNEL 10
11 = PPM CHANNEL 11
12 = PPM CHANNEL 12
Mapping example:
$123456789111CH
*/
// Local file variables
//
int frameNumber = 0; // Frame count since last debug serial output
char serial_data[101]; // Array for serial-data
unsigned char serial_index = 0; // How many bytes have been received?
char string_started = 0; // Only saves data if string starts with right byte
unsigned char channel_mapping[13];
char outputMag = 0; // Stream magnetometer data to host
char outputAcc = 0; // Stream accelerometer data to host
char outputMagAcc = 0; // Stream mag and accell data (for calibration on PC)
char outputTrack = 0; // Stream angle data to host
// Keep track of button press
char lastButtonState = 0; // 0 is not pressed, 1 is pressed
unsigned long buttonDownTime = 0; // the system time of the press
char pauseToggled = 0; // Used to make sure we toggle pause only once per hold
char ht_paused = 0;
// External variables (defined in other files)
//
extern unsigned char PpmIn_PpmOut[13];
extern char read_sensors;
extern char resetValues;
extern char tiltInverse;
extern char rollInverse;
extern char panInverse;
// Settings (Defined in sensors.cpp)
//
extern float tiltRollBeta;
extern float panBeta;
extern float gyroWeightTiltRoll;
extern float GyroWeightPan;
extern int servoPanCenter;
extern int servoTiltCenter;
extern int servoRollCenter;
extern int panMaxPulse;
extern int panMinPulse;
extern int tiltMaxPulse;
extern int tiltMinPulse;
extern int rollMaxPulse;
extern int rollMinPulse;
extern float panFactor;
extern float tiltFactor;
extern float rollFactor;
extern unsigned char servoReverseMask;
extern unsigned char htChannels[];
extern float gyroOff[];
extern float magOffset[];
extern int accOffset[];
// End settings
//--------------------------------------------------------------------------------------
// Func: setup
// Desc: Called by Arduino framework at initialization time. This sets up pins for I/O,
// initializes sensors, etc.
//--------------------------------------------------------------------------------------
void setup()
{
Serial.begin(SERIAL_BAUD);
pinMode(9,OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
// Set all other pins to input, for safety.
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(6,INPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
// Set button pin to input:
pinMode(BUTTON_INPUT,INPUT);
// Set internal pull-up resistor.
digitalWrite(BUTTON_INPUT,HIGH);
digitalWrite(0,LOW); // pull-down resistor
digitalWrite(1,LOW);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
pinMode(ARDUINO_LED,OUTPUT); // Arduino LED
digitalWrite(ARDUINO_LED, HIGH);
#if FATSHARK_HT_MODULE
pinMode(BUZZER,OUTPUT); // Buzzer
digitalWrite(BUZZER, HIGH);
#endif
// Give it time to be noticed, then turn it off
delay(200); // Note: only use delay here. This won't work when Timer0 is repurposed later.
digitalWrite(ARDUINO_LED, LOW);
#if FATSHARK_HT_MODULE
digitalWrite(BUZZER, LOW);
#endif
InitPWMInterrupt(); // Start PWM interrupt
Wire.begin(); // Start I2C
// If the device have just been programmed, write initial config/values to EEPROM:
if (EEPROM.read(0) != 8)
{
//#if (DEBUG)
Serial.println("New board - saving default values!");
//#endif
InitSensors();
#if (ALWAYS_CAL_GYRO)
SetGyroOffset();
#endif
SaveSettings();
SaveMagData();
SaveAccelData();
}
GetSettings(); // Get settings saved in EEPROM
InitSensors(); // Initialize I2C sensors
CalibrateMag();
ResetCenter();
InitTimerInterrupt(); // Start timer interrupt (for sensors)
}
//--------------------------------------------------------------------------------------
// Func: loop
// Desc: Called by the Arduino framework once per frame. Represents main program loop.
//--------------------------------------------------------------------------------------
void loop()
{
// Check input button for reset/pause request
char buttonPressed = (digitalRead(BUTTON_INPUT) == 0);
if ( buttonPressed && lastButtonState == 0)
{
resetValues = 1;
buttonDownTime = 0;
lastButtonState = 1;
}
if ( buttonPressed )
{
if ( !pauseToggled && (buttonDownTime > BUTTON_HOLD_PAUSE_THRESH) )
{
// Pause/unpause
ht_paused = !ht_paused;
resetValues = 1;
pauseToggled = 1;
}
}
else
{
pauseToggled = 0;
lastButtonState = 0;
}
// All this is used for communication with GUI
//
if (Serial.available())
