0

I am trying to compile an Arduino program that takes analog input. However, when I declare multiple global variables, it often will not compile and because it throws an error that the variables aren't within scope of the functions within the program. I am not super familiar with Arduino IDE, but this doesn't programmatically make sense to me.

This is the program:

/*
*  By Hannah Perner-Wilson, www.plusea.at
*  Modified 3/30/2012 By Brian E Kaminski, www.AdvancerTechnologies.com
*
*  IMPORTANT!!:
*  Scroll down to set your serial port
*  Scroll down to set your thresholds
*/

import processing.serial.*;

// definition of window size
// you can change the size of the window as you like
// the thresholdGraph will be scaled to fit
// the optimal size for the thresholdGraph is 1000 x 400
int xWidth = 1200;
int yHeight = 750;

// xPos input array, using prefix
int[] xPosArr= {0,0,0,0,0,0}; 

// 
int[] messageArr= {0,0,0,0,0,0}; 

// Arrays for threshholding
int[] threshMax= {0,0,0,0,0,0}; 
int[] threshMin= {0,0,0,0,0,0}; 

// variables for serial connection. portname and baudrate are user specific
Serial port1;

//Set your serial port here (look at list printed when you run the application once)
String V3 = Serial.list()[1];
String portname1 = V3;
int baudrate = 9600;

int prefix = 10001;
boolean myCatch = false;
String serialIN = "";
String serialINPUT = ""; 
String buffer = ""; 
int value = 0; 

// ThresholdGraph draws grid and poti states
ThresholdGraph in;

void setup(){
  // set size and framerate
  size(xWidth, yHeight);
  frameRate(25);
  background(255);
  strokeWeight(5);
  stroke(0);
  smooth();
  strokeCap(ROUND);

  // establish serial port connection      
  port1 = new Serial(this, portname1, baudrate);
  port1.bufferUntil('\n') ;
  println(Serial.list());  // print serial list

  // create DisplayItems object
  in = new ThresholdGraph();

  // THRESHOLD VALUES:
  // using the thresholdGraph you can determine the MIN and MAX values
  // of your sensors. Enter these here. They must lie between 0 and 1000.

    //MIN trashhold
    threshMin[0] = 20;   // one
    threshMin[1] = 20;   // two
    threshMin[2] = 20;   // three
    threshMin[3] = 20;   // four
    threshMin[4] = 20;   // five
    threshMin[5] = 20;   // six

    //MAX trashhold
    threshMax[0] = 600;   // one
    threshMax[1] = 600;   // two
    threshMax[2] = 600;   // three
    threshMax[3] = 600;   // four
    threshMax[4] = 600;   // five
    threshMax[5] = 600;   // six
}//end setup

// draw listens to serial port, draw 
void draw(){

  // listen to serial port and trigger serial event  
  while(port1.available() > 0){
        serialIN = port1.readStringUntil('\n');
        //println((int)float(serialIN));
        if(serialIN != "")
          serialEvent(serialIN);  
        else
          Serial.println("found empty");
        }

  // threshold serial input  
  threshHolding();  

  // draw serial input
  in.update();
}//end draw()

The error that are being thrown are:

testproject.ino:100:17: error: 'threshHolding' was not declared in this scope
testproject.ino:103:3: error: 'in' was not declared in this scope
Error compiling.
  • 2
    Looks more like a Processing sketch. Where is the threshHolding function defined? (PS threshHolding and in are functions, not variables) – Gerben Apr 20 '15 at 19:05
  • Agreed. It looks like that's a Processing sketch which was written to communicate with an Arduino. Perhaps the wrong code was added to the question? – Peter Bloomfield Apr 20 '15 at 20:44
  • I thought that "processing.serial" does not need to be imported in a .ino code? – Mathsman 100 Apr 21 '15 at 10:27
  • Can anyone answer why that has been written ? – Mathsman 100 Apr 21 '15 at 10:28
  • @Gerben , Do you know why? – Mathsman 100 Apr 21 '15 at 10:28
2

The problem is that this is not an Arduino Sketch, but a processing file which is noted by the initial import statement that is Java based. Because the Arduino IDE is not very sophisticated, it didn't shout out obvious errors such as import type not defined or even ThresholdGraph not defined.

To use this file it is necessary to use the following IDE: https://processing.org/reference/environment/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.