Created
August 22, 2015 20:19
-
-
Save pingud98/dd84176eda4237d17c9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x; // read value | |
int adcloopctr; | |
unsigned long values[100]; | |
const int eventtrigger = 49; | |
boolean eventhappened = false; | |
int sampledepth = 10; | |
int printctr = 0; | |
int readoutctr; | |
void setup() | |
{ | |
// analogReference(INTERNAL); | |
pinMode(eventtrigger, INPUT); | |
attachInterrupt(eventtrigger, monkey, FALLING); | |
Serial.begin(115200); // initialize the serial port: | |
REG_ADC_MR = 0x10380180; // change from 10380200 to 10380180, 1 is the PREESCALER and 8 means FREERUN | |
ADC -> ADC_CHER = 0x80; // enable ADC on pin A0 | |
eventhappened = false; | |
adcloopctr=0; | |
Serial.println("Alive"); | |
} | |
void loop() { | |
//unsigned long t = micros(); // init time an elapsed time, in micro seconds | |
//for(i = 0; i < 1000; i++) { | |
// instrucction to measure | |
while((ADC->ADC_ISR & 0x80)==0); // wait for conversion | |
values[adcloopctr] = ADC->ADC_CDR[7]; // read value A0 | |
if (eventhappened){ | |
//Serial.println("Event"); | |
//for (int printctr = adcloopctr+1; printctr+1 < sampledepth+adcloopctr; printctr++) { | |
//Serial.print(printctr); | |
//Serial.print(", "); | |
//if (printctr > sampledepth){ | |
//Serial.println(values[(printctr)]); | |
//Serial.println(values[(printctr)]); | |
//} | |
//printctr = ++printctr % sampledepth; | |
readoutctr=10; | |
for (int firsthalf=adcloopctr+1; firsthalf<sampledepth; firsthalf++) | |
{ | |
Serial.print(readoutctr); | |
Serial.print(", "); | |
Serial.println(values[firsthalf]); | |
readoutctr--; | |
} | |
for (int secondhalf=0; secondhalf<adcloopctr+1; secondhalf++) | |
{ | |
Serial.print(readoutctr); | |
Serial.print(", "); | |
Serial.println(values[secondhalf]); | |
readoutctr--; | |
} | |
eventhappened = false; | |
//delay(200); | |
} | |
adcloopctr++; | |
if (adcloopctr==sampledepth) { | |
adcloopctr=0; | |
} | |
} | |
void monkey() | |
{ | |
//Serial.println("trigger"); | |
eventhappened = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment