I am writing the code to take the derivative of a signal but when I go to verify it I get the following message:
"In function 'void loop()':
Derivative:29: error: 'Sensor_Data' was not declared in this scope
Sensor_Data = analogRead(AnalogPin);
^
Derivative:29: error: 'AnalogPin' was not declared in this scope
Sensor_Data = analogRead(AnalogPin);
^
Derivative:30: error: 'x' was not declared in this scope
x = Sensor_Data;
^
Derivative:31: error: 'Rate' was not declared in this scope
delay(Rate);
^
Derivative:33: error: 'y' was not declared in this scope
y = Sensor_Data;
^
Derivative:38: error: 'Derivative' was not declared in this scope
Derivative = (y - x)/(Rate_s)
^
Derivative:38: error: 'Rate_s' was not declared in this scope
Derivative = (y - x)/(Rate_s)
^
exit status 1
'Sensor_Data' was not declared in this scope"
I don't really know why I am getting this message and I checked to make sure each variable was spelled the correct way.
Here is my code:
void setup()
{
int AnalogPin = 0; //The input to the sensor data.
float Sensor_Data = 0.0000;
int Rate = 1000; //This is an arbitrary value to distinguish
//the window size of the sensor data.
float Rate_s = 1.00; //This is the sample rate in seconds
int C = 1000; //Constant to change Rate into seconds
float Derivative = 0.0000;
float x;
float y;
//Setup the switch controlling the machine. LOW implies that the
//trigger has not been hit and that the machine should keep operating.
//HIGH implies that the trigger has been hit and that the machine
//should stop operating(or do a specific action such as record this
//moment in memory etc...)
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop()
{
//Average Data first. The Due can sample at 100 kHz without any
//tampering within the code. To sample at a higher rate, change
//the analog.Read() function in the setup.
Sensor_Data = analogRead(AnalogPin);
x = Sensor_Data;
delay(Rate);
Sensor_Data = analogRead(AnalogPin);
y = Sensor_Data;
//Take the derivative by using the algebraic equation for slope
//rise/run.
Derivative = (y - x)/(Rate_s);
//or instead multiply by a constant, c = 1000 for millisecond
//delays or c = 100,000 for microsecond delays.
Derivative = (y - x)/(Rate * C);
//The trigger for this application is when the derivative of the RMS of
//the signal crosses 0. Here you can make the code do something when the
//trigger is hit. Right now all it does it stop the machine.
if(Derivative > 0)
{
digitalWrite(13, HIGH);
}
}