예제 #1
0
/**
 * Joystick
 */
void SkaarhojUtils::joystick_init(int tolerance, uint8_t analogInputPinHorizontal, uint8_t analogInputPinVertical, uint8_t digitalInputPin)	{

		// Configuration constants, should have setter-methods:
	_joystick_analogInputPin[0] = analogInputPinHorizontal;
	_joystick_analogInputPin[1] = analogInputPinVertical;
	_joystick_digitalInputPin = digitalInputPin;
	_joystick_tolerance = tolerance; 
	
	pinMode(analogInputPinHorizontal, INPUT);
	pinMode(analogInputPinVertical, INPUT);
	pinMode(digitalInputPin, INPUT_PULLUP);

		// Internal variables during operation:
	_joystick_previousPosition[0] = -1000;
	_joystick_previousPosition[1] = -1000;
	_joystick_previousValue[0] = -1000;
	_joystick_previousValue[1] = -1000;
	
		// Reset:
	_joystick_centerValue[0] = analogRead(_joystick_analogInputPin[0]);
	_joystick_centerValue[1] = analogRead(_joystick_analogInputPin[1]);
	joystick_hasMoved(0);
	joystick_hasMoved(1);
	
	Serial.print("Center values: ");
	Serial.print(_joystick_centerValue[0]);
	Serial.print(",");
	Serial.print(_joystick_centerValue[1]);
	Serial.println();
}
/**
 * Joystick
 * i2cAddress: 0-3
 */
void SkaarhojAnalog::joystick_init(int tolerance, uint8_t i2cAddress, uint8_t index)	{

	ADS7828 analogConv; // Address
	_analogConv = analogConv;
	_analogConv.init(i2cAddress);

	_joystick_index = index;
	_joystick_tolerance = tolerance; 
	
		// Internal variables during operation:
	_joystick_previousPosition[0] = -1000;
	_joystick_previousPosition[1] = -1000;
	_joystick_previousPosition[2] = -1000;
	_joystick_previousValue[0] = -1000;
	_joystick_previousValue[1] = -1000;
	_joystick_previousValue[2] = -1000;
	
		// Reset:
	_joystick_centerValue[0] = joystick_AnalogRead(0);
	_joystick_centerValue[1] = joystick_AnalogRead(1);
	_joystick_centerValue[2] = joystick_AnalogRead(2);
	joystick_hasMoved(0);
	joystick_hasMoved(1);
	joystick_hasMoved(2);
	
	Serial.print("Center values: ");
	Serial.print(_joystick_centerValue[0]);
	Serial.print(",");
	Serial.print(_joystick_centerValue[1]);
	Serial.print(",");
	Serial.print(_joystick_centerValue[2]);
	Serial.println();
}