Well, I had thought that once j>255 the code would never leave this while loop and would just output the data stored in the array. I realize that the first for loop should have been outside the while loop for this to work but I had tried that previously and I still got the same issue. Like the code below:
#include <DueAdcFast.h>
DueAdcFast DueAdcF(1024);
// 1024 measures is dimension of internal buffer. (min is 1024)
unsigned long period;
unsigned long spaceLength;
unsigned long pulseWidth;
unsigned long oldPeriod = 0;
int inputSignal;
int start1;
unsigned long endTime;
unsigned long lowTime;
unsigned long midTime;
int frequencyINPUT;
volatile int x;
int b;
int y;
int i=0;
int j;
int z;
uint32_t sensorSignal; // the variables of your code.
float getround;
int rounded;
int finalval;
int pulseWidths[255];
void setup() {
start1 = 0;
Serial.begin(115200);
// indicate the pins to be used with the library.
DueAdcF.EnablePin(A7);
//DueAdcF.EnablePin(A1);
// indicate at what speed in the background
DueAdcF.Start1Mhz(); // max speed 1Mhz (sampling rate)
//DueAdcF.Start(); // normal speed 667 Khz (sampling rate)
//DueAdcF.Start(255); // with prescaler value form 3 to 255.
// 255 is approx. 7812 Hz (sampling rate)
}
// these 3 lines of code are essential for the functioning of the library
// you don't call ADC_Handler.
// is used automatically by the PDC every time it has filled the buffer
// and rewrite buffer.
//
void ADC_Handler() {
DueAdcF.adcHandler();
}
void loop() {
//y = micros();
sensorSignal = DueAdcF.ReadAnalogPin(A7);
if (sensorSignal < 1800 && start1 == 0) //detects first tooth and starts to read the output signal from the sensor (PART 1 ON DIAGRAM 1.)
{
start1=1;
}
if (sensorSignal > 1800 && start1 == 1) //reads that the sensor has gone low and records the time (PART 2 ON DIAGRAM 1.)
{
start1=2;
lowTime = micros()*0.01;
}
if (sensorSignal < 1800 && start1 == 2) //reads that the sensor has gone high and records the time (PART 3 ON DIAGRAM 1.)
{
start1=3;
midTime = micros()*0.01;
}
if (sensorSignal > 1800 && start1 == 3) //reads that the sensor has gone high and records the time (PART 1 ON DIAGRAM 1.)
{
start1=1;
endTime = micros()*0.01;
spaceLength = endTime - midTime;
period = endTime - lowTime;
pulseWidth = period - spaceLength;
}
i
Serial.print(sensorSignal);
Serial.println();
for ( i = 0; i < 254; i = i + 1) {
pulseWidths[i] = pulseWidth;
}
while(i>255)
{
for ( z = 0; z < 254; z = z + 1) {
Serial.println(pulseWidths[z]);
}
}
}