#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <avr/wdt.h>
#include "SerialCom.h"
#include <RunningAverage.h>
int centerFreq = 6300;
double _gain = 1.2;
unsigned int sampleSize = 24;
// GUItool: begin automatically generated code
AudioInputAnalogStereo adcs1; //xy=200,582
AudioFilterBiquad biquad1L; //xy=400,521
AudioAmplifier amp1L; //xy=542,513
AudioAnalyzePeak peakL; //xy=789,472
AudioOutputUSB usb1; //xy=834.0000114440918,538.0000085830688
AudioConnection patchCord1(adcs1, 0, biquad1L, 0);
AudioConnection patchCord2(biquad1L, amp1L);
AudioConnection patchCord3(amp1L, peakL);
AudioConnection patchCord4(amp1L, 0, usb1, 0);
AudioConnection patchCord5(amp1L, 0, usb1, 1);
// GUItool: end automatically generated code
int monoPeak; //for peak detection
double mapV = 0.0; //boost voltage
double afrV = 0.0; //AFR voltage
double auxV = 0.0; //Aux volt in
double injectorDuty = 0;
double low, high;
int cycles = 10;
int triggerPin = 3;
double refVolts = 0.0; //Ref volts
double revPerSpark = 2.500;
unsigned long lastTime;
unsigned long sparkTime;
volatile double rpm = 0;
int boostPin = A3;
const int afrPin = A1;
const int output5V = A2;
const int auxPin = A6;
int timeout = 0;
int RPMReset = 0;
const int ledpin = LED_BUILTIN;
void setup()
{
pinMode(ledpin, OUTPUT);
pinMode(3, INPUT_PULLUP);
AudioMemory(6);
amp1L.gain(_gain);
Serial.begin(250000);
lastTime = sparkTime = micros();
}
// for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.
elapsedMillis fps;
int settingCheckCounter = 0;
void loop()
{
Serial.print("Works up to here");
//---------READ BOOST---------//
mapV = 0; //reset
mapV = analogRead(boostPin); //A3 ?voltage divider?
mapV = mapDouble(mapV, 0, 1023, 0, 5); //map to reference voltage
afrV = analogRead(afrPin);
afrV = mapDouble(afrV, 0, 1023, 0.00, 5); //map to reference voltage
}
double mapDouble(double x, double in_min, double in_max, double out_min, double out_max)
{
if (x > in_max)
x = in_max;
if (x < in_min)
x = in_min;
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void SendDataToPC()
{
Serial.println("Works up to this line");
}