Here's the semi-full sketch. The full one has two sets of arrays, each with 1200 numbers.
#include <PWM.h>
int dir = 12;
int motorSpeedPin = 9;
int32_t frequency = 20000; //frequency (in Hz)
int forward = LOW;
int reverse = HIGH;
int motorSpeed = 180;
int numDensityReading = 1200;
int protonDensity[] = {
1.5, 1.5, 1.2,
1.1,
1.2,
1.6,
1.4,
1.6,
-9999.9,
-9999.9,
1.8,
2.1,
1.5,
1.8,
1.7,
1.3,
1.5, };
int numSpeedReadings = 1200;
int bulkSpeed[] = {
3346, 3320, 3340,
3334,
3301,
3287,
3188,
3156,
2836,
2875, };
int i = 0;
int ii = 0;
int bS;
int pD;
long lastReadingDelay = 0;
long readingDelay = 10000;
void setup(){
Serial.begin(9600);
InitTimersSafe();
bool success = SetPinFrequencySafe(motorSpeedPin, frequency);
if(success) {
Serial.println("Frequency Successfully Set.");
}
pinMode(dir, OUTPUT);
// pinMode(button0, INPUT_PULLUP);
// pinMode(button1, INPUT_PULLUP);
digitalWrite(dir, forward);
}
void loop(){
if(millis() - lastReadingDelay > readingDelay){
i = i ++;
// ii = ii ++;
bS = bulkSpeed[i];
// pD = protonDensity[i];
bS = constrain(bS, 2883, 3000);
bS = map(bS, 2883, 3000, 180, 255);
lastReadingDelay = millis();
// Serial.print("bulkSpeed = ");
Serial.println(bS);
// Serial.print(",");
// Serial.println(pD);
analogWrite(motorSpeedPin, bS);
}
}