Skip to content

Instantly share code, notes, and snippets.

@jstults
Created March 18, 2012 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstults/2074289 to your computer and use it in GitHub Desktop.
Save jstults/2074289 to your computer and use it in GitHub Desktop.
Sampling Arduino Pins Quickly
/*
Sampling with the Arduino
based on examples from
http://sites.goggle.com/site/MeasuringStuff
*/
#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// the famous LED on digital pin 13
byte ledPin = 13;
// our array size
int i=0;
int size=64;
unsigned long time[64];
unsigned long time2[32];
unsigned int rawdata[32];
unsigned int rawdata2[64];
void setup() {
// initialize both serial ports:
Serial.begin(9600);
// signal ready to start by turning on LED 13
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
#if FASTADC
// set prescale to 16
cbi(ADCSRA,ADPS2) ;
sbi(ADCSRA,ADPS1) ;
sbi(ADCSRA,ADPS0) ;
#endif
}
void loop() {
for (i=0 ;i<size;i++){
time[i]=micros();
// rawdata[i]=analogRead(0);
// time2[i]=micros();
rawdata2[i]=analogRead(2);
Serial.print(micros());
Serial.print(" , ");
Serial.print(analogRead(2));
Serial.println("");
}
// for (i=0;i<size;i++) {
// Serial.print(time[i]);
// Serial.print(" , ");
// Serial.print(rawdata[i]);
// Serial.print(" , ");
// Serial.print(time2[i]);
// Serial.print(" , ");
// Serial.println(rawdata2[i]);
// }
Serial.println("");
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment