/* AtoD for Seismometer - mimics SEP UK interface 12 Aug 2015 created (without averaging) */ //the setup routine runs once when you press reset: void setup() { // initialize serial ommunication at 9600 bits per second: Serial.begin(9600); //set timer1 interrupt at 20Hz TCCR1A = 0; // set entire TCCR1A register to 0 TCCR1B = 0; // same for TCCR1B TCNT1 = 0; //initialize counter value to 0 //Send samples every 6 Hz (typical seismograph) OCR1A = 2603; // turn on CTC mode TCCR1B |= (1 << WGM12); // Set CS10 and CS12 bits for 1024 prescaler TCCR1B |= (1 << CS12) | (1 << CS10); // enable timer compare interrupt TIMSK1 |= (1 << OCIE1A); sei();//allow interrupts } ISR(TIMER1_COMPA_vect){ // Timer1's interrupt // send the output to the com port every interrupt // read the input on analog pin 1: int sensorValue = analogRead(A1); // CR char chrValueCR = 13; // Convert the analog reading (which goes from 0 - 1023 to // a voltage (0 - 5V): //float voltage = sensorValue * (5.0 / 1023.0); // for Seismometer SEP model range is -32,768 to + 32,768 int voltage = (sensorValue-511) * 63; //63 is to keep from rolling the integer Serial.print(voltage); Serial.print(chrValueCR); } // the loop routine runs over and over again forever: void loop() { // everything happens in the interrupt }