Impact location, using four sound sensors.

Marceldv:
The digital input i need to improve the acquisition speed..

I wrote some code to get faster digital reads.
You will initialize the drbit and drport arrays using initDigitalRead() in setup. Then, when calling digitalRead2() you can get 265Khz max sample rate (instead of 166Khz).

for faster analogread refer to Index of /jayduino/fasterAnalogRead which gets you about 72Khz as sample rate (theoretically 83Khz, but it starts to get crappy) .

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
static inline void turnOffPWM(uint8_t timer)
{
	if (timer == TIMER1A) cbi(TCCR1A, COM1A1);
	if (timer == TIMER1B) cbi(TCCR1A, COM1B1);

#if defined(__AVR_ATmega8__)
	if (timer == TIMER2) cbi(TCCR2, COM21);
#else
	if (timer == TIMER0A) cbi(TCCR0A, COM0A1);
	if (timer == TIMER0B) cbi(TCCR0A, COM0B1);
	if (timer == TIMER2A) cbi(TCCR2A, COM2A1);
	if (timer == TIMER2B) cbi(TCCR2A, COM2B1);
#endif

#if defined(__AVR_ATmega1280__)
	if (timer == TIMER3A) cbi(TCCR3A, COM3A1);
	if (timer == TIMER3B) cbi(TCCR3A, COM3B1);
	if (timer == TIMER3C) cbi(TCCR3A, COM3C1);
	if (timer == TIMER4A) cbi(TCCR4A, COM4A1);
	if (timer == TIMER4B) cbi(TCCR4A, COM4B1);
	if (timer == TIMER4C) cbi(TCCR4A, COM4C1);
	if (timer == TIMER5A) cbi(TCCR5A, COM5A1);
	if (timer == TIMER5B) cbi(TCCR5A, COM5B1);
	if (timer == TIMER5C) cbi(TCCR5A, COM5C1);
#endif
}


uint8_t drbit[50];
uint8_t drport[50];

int initDigitalRead(uint8_t pin)
{
   uint8_t timer = digitalPinToTimer(pin);
   drbit[pin] = digitalPinToBitMask(pin);
   drport[pin] = digitalPinToPort(pin);
   if (timer != NOT_ON_TIMER) turnOffPWM(timer);
}


int digitalRead2(uint8_t pin)
{
   if (*portInputRegister(drport[pin]) & drbit[pin]) return HIGH;
   return LOW;
}