0% found this document useful (0 votes)
6 views

Code Arduino - P27838123097

Uploaded by

maria tokan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Code Arduino - P27838123097

Uploaded by

maria tokan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

const byte adcPin = 0; // A0

const int ledPin = 9;

const int MAX_RESULTS = 200;

volatile int results [MAX_RESULTS];


volatile int resultNumber;

// ADC complete ISR


ISR (ADC_vect)
{
//digitalWrite(ledPin, HIGH);
//delayMicroseconds(10);
if (resultNumber >= MAX_RESULTS)
ADCSRA = 0; // turn off ADC
else
results [resultNumber++] = ADC;
// digitalWrite (ledPin, LOW);
//delayMicroseconds(10);
// digitalWrite(ledPin, !digitalRead(ledPin));
} // end of ADC_vect

EMPTY_INTERRUPT (TIMER1_COMPB_vect);

void setup ()
{
pinMode(ledPin, OUTPUT);
// digitalWrite(ledPin, LOW);
Serial.begin (115200);
// Serial.println ();

// reset Timer 1
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
TCCR1B = bit (CS11) | bit (WGM12); // CTC, prescaler of 8
TIMSK1 = bit (OCIE1B); // WTF?
OCR1A = 399; //
OCR1B = 399; // 250 uS - sampling frequency 4 kHz

ADCSRA = bit (ADEN) | bit (ADIE) | bit (ADIF); // turn ADC on, want
interrupt on completion
ADCSRA |= bit (ADPS2); // Prescaler of 16
ADMUX = bit (REFS0) | (adcPin & 7);
ADCSRB = bit (ADTS0) | bit (ADTS2); // Timer/Counter1 Compare Match B
ADCSRA |= bit (ADATE); // turn on automatic triggering

// wait for buffer to fill


while (resultNumber < MAX_RESULTS)
{ }

for (int i = 0; i < MAX_RESULTS; i++)


Serial.println (results [i]);
// digitalWrite(ledPin, LOW);
} // end of setup

void loop () {
}

You might also like