Hello everyone. I want you to help me with a compilation problem that I can't solve. I'm using Arduino IDE 1.8.5. I am attaching the code and the error. I hope to find an answer. Thank you.
*/
#include <EEPROM.h>
#include <Wire.h>
//use #include <LiquidCrystal.h> if you don't have I2C LCD
#include <LiquidCrystal_I2C.h>
#include <MenuSystem.h>
#include "defs.h"
#include "VdiLcd.h"
#include "params.h"
#include "menu.h"
#include "encoder.h"
//use "LiquidCrystal" if you don't have I2C
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
CVDILcd vdi(&lcd);
CParameters params;
extern MenuSystem ms;
///////////////////////////////////////////////////////////////////////////////////////////////////////
//signal processing
bool generateReading(int* pPhase, int* pStrength, unsigned char* signalValues, bool* pbadReading)
{
#define SAMPLE_BUFFER_SIZE 350
unsigned char strenth[SAMPLE_BUFFER_SIZE] = {0,};
unsigned char angle[SAMPLE_BUFFER_SIZE] = {0,};
int index = 0;
bool enoughSamples = false;
unsigned long startTime = millis();
bool needToClearLastResult = true;
bool retValue = true;
while(1)
{
//digitalWrite(8, LOW); //debug
//delayMicroseconds(100);//debug
//digitalWrite(8, HIGH); //debug
//check the encoder and break out of the processing on user button press
if(checkEncoder())
{
params.m_showVDI = false;
retValue = false;
break;
}
//sample signals
float X = 0.0F;
float R = 0.0F;
const int SAMPLING_LOOP = params.m_readingSamples;
for(int n(0);n<SAMPLING_LOOP;n++)
{
X += analogRead(XPin);
R += analogRead(RPin);
}
X /= SAMPLING_LOOP;
R /= SAMPLING_LOOP;
//digitalWrite(8, LOW); //debug
//Serial.print("------------------------------------------\r\n");
//Serial.print(X - params.m_XBias);
//Serial.print(",");
//Serial.print(R - params.m_RBias);
//Serial.print("\r\n");
//delay(5);
//continue;
//if opamp is saturated; break and report it
if(X >= params.m_maxSignal || R >= params.m_maxSignal)
{
*pbadReading = true;
break;
}
//bring to "virtual ADC zero"
X = X - params.m_XBias;
R = R - params.m_RBias;
//screen out samples using signal R polarity as set in params
// 0 - use any polarity
//-1 - use only negative R
// 1 - use only positive R
if( (params.m_sigPolarity<0 && R>0) || (params.m_sigPolarity>0 && R<0) )
{
X = 0.0F;
R = 0.0F;
}
//phase in degrees
int phase = ( (X == 0.0F && R == 0.0F) ? 0 : atan2(X, R) * 57.295F );
if(phase < -90)
phase = -90;
else if(phase > 90)
phase = 90;
angle[index] = phase + 90;
strenth[index] = int(sqrt(X*X+R*R));
index++;
//ring buffer; wrap around
if(index >= SAMPLE_BUFFER_SIZE)
{
enoughSamples = true;
index = 0;
}
if(!enoughSamples)
continue;
//find peak signal
unsigned char maxVal = 0;
int maxIndex = -1;
for(int n(0); n<SAMPLE_BUFFER_SIZE; n++)
{
if(strenth[n] > maxVal)
{
maxVal = strenth[n];
maxIndex = n;
}
}
//is the peak strong enough
if(maxVal < params.m_minSignal)
{
//no strong signal is present; its a good time to clear LCD if needed
if(needToClearLastResult && (millis() - startTime) > 5000)
{
unsigned char empty[40]={0};
vdi.updateVDI(params.m_vdiStyle, 0, 0, empty, false);
needToClearLastResult = false;
}
continue;
}
//where in the buffer is the peak
int dist = index - maxIndex;
if(dist < 0)
dist = SAMPLE_BUFFER_SIZE + dist;
//check if the peak is in the middle of the buffer
if(dist != SAMPLE_BUFFER_SIZE/2)
continue;
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//we have strong enough peak in the middle of sampling buffer
//calculate the result and break the loop
float angleAvg = 0.0F;
float strengthAvg = 0.0F;
int avgSamples = 0;
const int reach = 1;
int n = maxIndex - reach;
while(avgSamples < (reach*2 + 1))
{
if(n<0)
n += SAMPLE_BUFFER_SIZE;
else if(n>=SAMPLE_BUFFER_SIZE)
n %= SAMPLE_BUFFER_SIZE;
angleAvg += (int(angle[n]) - 90);
strengthAvg += strenth[n];
avgSamples++;
n++;
}
*pPhase = angleAvg/avgSamples;
*pStrength = strengthAvg/avgSamples;
//sound handling
if(params.m_soundOn)
tone(SND_PIN, *pPhase <= 0 ? SND_LOW_TONE : SND_HIGH_TONE, SND_LENGTH);
//prepare data for the 40x8 graph
int i = 0;
int k = index;
const int inc = SAMPLE_BUFFER_SIZE/40;
while(i<40)
{
if(k>=SAMPLE_BUFFER_SIZE)
k -= SAMPLE_BUFFER_SIZE;
signalValues[i] = float(strenth[k])/float(maxVal) * 8;
k+=inc;
i++;
}
//measurement completed; break the loop
break;
}
return retValue;
}
////////////////////////////////////////////////////////////////////////////////////
// Standard arduino functions
void setup()
{
//restore from EEPROM
params.loadParams();
//LCD init
lcd.begin(16,2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(params.m_LcdBacklight ? LED_ON : LED_OFF);
//create menu
createVDIMenu();
//Encoder setup
pinMode(PIN_ENC1, INPUT);
pinMode(PIN_ENC2, INPUT);
pinMode(PIN_EBTN, INPUT);
pinMode(PIN_LED1, OUTPUT);
digitalWrite(PIN_ENC1, HIGH);
digitalWrite(PIN_ENC2, HIGH);
digitalWrite(PIN_EBTN, HIGH);
attachInterrupt(0, intrEncChange1, CHANGE);
attachInterrupt(1, intrEncChange2, CHANGE);
checkEncoder();
//initialize LCD GUI
lcd.clear();
lcd.home();
lcd.setCursor(0,0);
lcd.print("VDI v0.3");
delay(1000);
unsigned char signalValues[40]={0};
params.m_showVDI = true;
vdi.reset();
vdi.updateVDI(params.m_vdiStyle, 0, 0, signalValues, false);
if(params.m_soundOn)
{
tone(SND_PIN, 700, 200);
delay(200);
}
//Serial.begin(115200);
}
void loop()
{
if(params.m_showVDI)
{
int phase(0.0F);
int strength(0);
unsigned char signalValues[40]={0};
bool badReading(false);
if(generateReading(&phase, &strength, signalValues, &badReading))
{
vdi.updateVDI(params.m_vdiStyle, phase, strength, signalValues, badReading);
}
}
else
{
encoderHandler();
}
}