added code to transmit sample frequency along with sample data (more compatibility between arduino and PC, and possibility to change sampling rate at run-time)
// how many samples we want to skip between two samples we keep (can be used to lower the sampling frequency)
#define SkipSamples 0
byteregularEncodedFrequency;
constintBufferSize=512;
bytebuffer1[BufferSize];
@ -38,11 +39,19 @@ void setup()
ADMUX|=(1<<REFS0);//set reference voltage
ADMUX|=(1<<ADLAR);//left align the ADC value- so we can read highest 8 bits from ADCH register only
ADCSRA|=(1<<ADPS2)|(0<<ADPS1)|(1<<ADPS0);//set ADC clock with 32 prescaler- 16mHz/32=500KHz ; 13 cycles for a conversion which means 38000 samples per second
intADPS=(1<<ADPS2)|(0<<ADPS1)|(1<<ADPS0);
ADCSRA|=ADPS;//set ADC clock with 32 prescaler- 16mHz/32=500KHz ; 13 cycles for a conversion which means 38000 samples per second
ADCSRA|=(1<<ADATE);//enabble auto trigger
ADCSRA|=(1<<ADIE);//enable interrupts when measurement complete