'maxValue' was not declared in this scope

Hi Arduino brains trust,

i have been getting this error, 'maxValue' was not declared in this scope, and have not been able to resolve?

Any ideas?

Cheers D

#include <Adafruit_PWMServoDriver.h>

#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_I2C_ByVac.h>
#include <LiquidCrystal_SI2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR1W.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <SI2CIO.h>
#include <SoftI2CMaster.h>

#include <Wire.h>
#include <lcd.h>
#include <liquidcrystal_i2c.h>
#include <adafruit_pwmservodriver.h>

#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int address = 0x27; // display i2c address

LiquidCrystal_I2C lcd(address,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define OPEN 230 //150 // this is the 'minimum' pulse length count (out of 4096)
#define CLOSED 412 //550 //600 // this is the 'maximum' pulse length count (out of 4096)
#define TS_CLOSED 240 // table saw closed
#define TS_OPEN 410 // table saw open
#define ROUTER_OPEN 100
#define ROUTER_CLOSED 335
#define SANDER_OPEN 100
#define SANDER_CLOSED 335

#define NUMBER_OF_TOOLS 6

int activeTool = 50;// a number that will never happen

const uint8_t bandsaw_gate = 0;
const uint8_t router_gate = 1;
const uint8_t tablesaw_gate = 2;
const uint8_t jointer_gate = 3;
const uint8_t planer_gate = 4;
const uint8_t sander_gate = 5;
//const uint8_t drum_sander_gate = 6;

String tools[] = {"Bandsaw", "Router", "Tablesaw", "Jointer", "Planer", "Sander", "Drum Sander"};
String ampText;
String toolText = "Tablesaw";

int voltSensor[] = {8,9,10,11,12,13,14,15};
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double ampThreshold = 1.0;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

// Dust Collector Relay Values
bool dc_running = false;
uint32_t dc_starttime1 = 0;
uint32_t dc_starttime2 = 0;
const int dc_relay_pin = 9;
const int RELAY_OFF = LOW;
const int RELAY_ON = HIGH;

uint32_t idle_start_time = 0;
const uint32_t IDLE_MAX = 5 * 60000; // 5 minutes

void displaythis(String line1, String line2)
{
lcd.home (); // go to top left position
lcd.clear();
lcd.print(line1);
lcd.setCursor(0,1);
lcd.print(line2);

Wire.beginTransmission(address); //Now check the I2C bus communications
Wire.endTransmission(); //Get the error code, if any.
}

void setup()
{
// pinMode(13,OUTPUT);
Serial.begin(9600);

pinMode(dc_relay_pin, OUTPUT);
digitalWrite(dc_relay_pin, LOW);

lcd.begin (20,4); //(How many columns, how many rows) in your display
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);

pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates

displaythis("Table Saw", "");
pwm.setPWM(bandsaw_gate, 0, CLOSED);
pwm.setPWM(router_gate, 0, ROUTER_CLOSED);
pwm.setPWM(tablesaw_gate, 0, TS_OPEN);
pwm.setPWM(jointer_gate, 0, CLOSED);
pwm.setPWM(planer_gate, 0, CLOSED);
pwm.setPWM(sander_gate, 0, SANDER_CLOSED);
// pwm.setPWM(drum_sander_gate, 0, CLOSED);

// for(int i=0;i<number_of_tools;i++) {="" pinmode(voltsensor[i],input);="" }="" }="" void="" opengate(int="" gate)="" {="" serial.println("opengate()");="" pwm.begin();="" pwm.setpwmfreq(60);="" analog="" servos="" run="" at="" ~60="" hz= "" updates="" switch="" (gate)="" {="" case="" 0:="" tooltext="Bandsaw" ;="" pwm.setpwm(bandsaw_gate,="" 0,="" open);="" delay(500);="" pwm.setpwm(router_gate,="" 0,="" router_closed);="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_closed);="" pwm.setpwm(jointer_gate,="" 0,="" closed);="" pwm.setpwm(planer_gate,="" 0,="" closed);="" pwm.setpwm(sander_gate,="" 0,="" sander_closed);="" pwm.setpwm(drum_sander_gate,="" 0,="" closed);="" break;="" case="" 1:="" tooltext="Router Table" ;="" pwm.setpwm(router_gate,="" 0,="" router_open);="" delay(500);="" pwm.setpwm(bandsaw_gate,="" 0,="" closed);="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_closed);="" pwm.setpwm(jointer_gate,="" 0,="" closed);="" pwm.setpwm(planer_gate,="" 0,="" closed);="" pwm.setpwm(sander_gate,="" 0,="" sander_closed);="" pwm.setpwm(drum_sander_gate,="" 0,="" closed);="" break;="" case="" 2:="" tooltext="Table Saw" ;="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_open);="" delay(500);="" pwm.setpwm(bandsaw_gate,="" 0,="" closed);="" pwm.setpwm(router_gate,="" 0,="" router_closed);="" pwm.setpwm(jointer_gate,="" 0,="" closed);="" pwm.setpwm(planer_gate,="" 0,="" closed);="" pwm.setpwm(sander_gate,="" 0,="" sander_closed);="" pwm.setpwm(drum_sander_gate,="" 0,="" closed);="" break;="" case="" 3:="" tooltext="Jointer" ;="" pwm.setpwm(jointer_gate,="" 0,="" open);="" delay(500);="" pwm.setpwm(bandsaw_gate,="" 0,="" closed);="" pwm.setpwm(router_gate,="" 0,="" router_closed);="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_closed);="" pwm.setpwm(planer_gate,="" 0,="" closed);="" pwm.setpwm(sander_gate,="" 0,="" sander_closed);="" pwm.setpwm(drum_sander_gate,="" 0,="" closed);="" break;="" case="" 4:="" tooltext="Planer" ;="" pwm.setpwm(planer_gate,="" 0,="" open);="" delay(500);="" pwm.setpwm(bandsaw_gate,="" 0,="" closed);="" pwm.setpwm(router_gate,="" 0,="" router_closed);="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_closed);="" pwm.setpwm(jointer_gate,="" 0,="" closed);="" pwm.setpwm(sander_gate,="" 0,="" sander_closed);="" pwm.setpwm(drum_sander_gate,="" 0,="" closed);="" break;="" case="" 5:="" tooltext="Sander" ;="" pwm.setpwm(sander_gate,="" 0,="" sander_open);="" delay(500);="" pwm.setpwm(bandsaw_gate,="" 0,="" closed);="" pwm.setpwm(router_gate,="" 0,="" router_closed);="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_closed);="" pwm.setpwm(jointer_gate,="" 0,="" closed);="" pwm.setpwm(planer_gate,="" 0,="" closed);="" pwm.setpwm(drum_sander_gate,="" 0,="" closed);="" break;="" *="" case="" 6:="" tooltext="Drum Sander" ;="" pwm.setpwm(drum_sander_gate,="" 0,="" open);="" delay(500);="" pwm.setpwm(bandsaw_gate,="" 0,="" closed);="" pwm.setpwm(router_gate,="" 0,="" router_closed);="" pwm.setpwm(tablesaw_gate,="" 0,="" ts_closed);="" pwm.setpwm(jointer_gate,="" 0,="" closed);="" pwm.setpwm(planer_gate,="" 0,="" closed);="" pwm.setpwm(sander_gate,="" 0,="" sander_closed);="" break;*="" }="" displaythis(tooltext,="" amptext);="" pwm.reset();="" }="" float="" currentsensorvalue[number_of_tools];="" void="" re adallvpp()="" {="" serial.println("readallvpp()");="" int="" readvalue;="" int="" maxvalue[]="{0," 0,="" 0,="" 0,="" 0,="" 0,="" 0,="" 0};="" store="" max="" value="" here="" int="" minvalue[]="{1024," 1024,="" 1024,="" 1024,="" 1024,="" 1024,="" 1024,="" 1024};="" store="" min="" value="" here="" uint32_t="" start_time="millis();" while((millis()-start_time)="" <="" 125)="" sample="" for="" .5="" sec="" {="" for="" (int="" tool="0;" tool="" <="" number_of_tools;="" tool++)="" {="" readvalue="analogRead(voltSensor[tool]);" see="" if="" you="" have="" a="" new="" maxvalue="" if="" (readvalue=""> maxValue[tool])
{
/*record the maximum sensor value*/
maxValue[tool] = readValue;
}
if (readValue < minValue[tool])
{
/*record the maximum sensor value*/
minValue[tool] = readValue;
}
}
}

Please read "Read this before posting a programming question" at the top of the forum and post your sketch- all of it- using code tags.

Second half.

// Subtract min from max
for (int tool = 0; tool < NUMBER_OF_TOOLS; tool++)
{
//Serial.println("#" + String(tool) + " Min: " + String(minValue[tool]) + " Max: " + String(maxValue[tool]));

currentSensorValue[tool] = ((maxValue[tool] - minValue[tool]) * 5.0) / 1024.0;
}
}

boolean checkForAmperageChange(int tool)
{
bool hasCurrent = false;

Voltage = currentSensorValue[tool];
VRMS = (Voltage / 2.0) * 0.707;
AmpsRMS = (VRMS * 1000) / mVperAmp;

hasCurrent = AmpsRMS > ampThreshold;
if (hasCurrent)
{
ampText = String(AmpsRMS) + " Amps";
}

return (hasCurrent);
}

void updateRelay(bool on)
{
if (on)
{
dc_starttime2 = 0;

if (!dc_running)
{
if (dc_starttime1 == 0)
{
dc_starttime1 = milli s();
}
else
{
if ((millis() - dc_starttime1) > 100)
{
dc_starttime1 = 0;
dc_running = true;
Serial.println("Turning relay on");
digitalWrite(dc_relay_pin,HIGH);
}
}
}

Serial.println("Setting Idle Start Time to zero.");
idle_start_time = 0; // make sure this gets reset since there is a tool running

return;
}
else
{
ampText = "Off";
dc_starttime1 = 0;

if (dc_running)
{

if (dc_starttime2 == 0)
{
dc_starttime2 = millis();
}
else
{
if ((millis() - dc_starttime2) > 4000)
{
dc_starttime2 = 0;
dc_running = false;
Serial.println("Turning relay off");
digitalWrite(dc_relay_pin,LOW);
}
}
}

// Check time out
if (idle_start_time == 0)
{
Serial.println("Setting Idle Start Time");
idle_start_time = millis();
}
return;
}
}

void loop() {
// put your main code here, to run repeatedly:
bool someToolIsOn = false;
readAllVPP();
//loop through tools and check
for(int i=0;i<number_of_tools;i++) {="" if(="" checkforamperagechange(i)){="" if="" (i="" !="activeTool)" {="" opengate(i);="" activetool="i;" }="" sometoolison="true;" }="" }="" updaterelay(sometoolison);="" delay(500);="" displaythis(tooltext,="" amptext);="" }="">
  1. Please please PLEASE learn to indent your code. It makes it a million times easier to read.

  2. I know it's commented out, but that for loop just before it is a nasty piece of work. If you intend on using it later, I can tell you for certain it will throw an error or 10

  3. It's showing "maxValue was not declared in this scope" because at literally no point do you declare it. If you wanted to declare it, change:

//here is where you put that code in point 2 (For loop of some description)
{
      /*record the maximum sensor value*/
      maxValue[tool] = readValue;
}

to:

/*record the maximum sensor value*/
      float maxValue[tool] = readValue;

On top of that what is "readValue"? Is it a function? If so, it needs to be readValue()

Also make sure to actually define what that is.

Also if you need help, please post full code in a single quote. "Second half" could mean anything. What about the error? What about the for loop (BTW comment out the brackets after the for loop or that'll throw an error too)?

What are you actually trying to do? It looks like you've just included every library you could find in the arduino library database, and it doesn't help us decode what the problem is because the whole thing should be throwing errors. Please be more specific next time

Technokid2000:
It looks like you've just included every library you could find in the arduino library database

If you do Sketch > Include Library > NewLiquidCrystal, the Arduino IDE automatically adds #include directives for all header files in the library's root source folder. So this is the cause of the ridiculous number of #include directives. It's certain that it's only necessary to #include one of the header files from the library.

The Arduino IDE does have a feature where the library author can specify which header files should be added by Sketch > Include Library > NewLiquidCrystal, but it looks like in this case the correct file to use depends on the application. So probably the best approach is to avoid using Sketch > Include Library > NewLiquidCrystal at all and instead use the example sketches as a reference for which #include directive to use.

There's absolutely no magic to Sketch > Include Library > NewLiquidCrystal. It just adds those #include directives to your sketch, nothing more. There is no difference in you just typing the #include directive in yourself.

Thank you to all for you advice and input.

I will continue to debug.

thank you

D