Hi everyone, I really need ur help in one part of the project I'm working on.
I have to convert the number of pulses a agricultural fertilizer machine gives me (I've already done the pulses counter sketch) into a volume of fertilizer (I have the quadratic equation wich is Y = (2E-05)*x^2 + 0.0017x - 0.0338 )
My question is: how could I write the code for having one variable input (the number of pulses ,the X on the equation, will be changing for every position of the machine) and have the result (Y) printed on the serial port.
Thanks PaulS for your help! I'll change those things, but what I need to know is how to declare the x as the number of pulses that the counter i made (This one, using the Encoder.h library and modifying it)
volatile int unsigned pulsos=0;
#include <Encoder.h>
Encoder myEnc(2, 6);
void setup() {
pinMode (13,INPUT);
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
long oldPosition = myEnc.read();
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
if (digitalRead (13)){ //when pin 13 is HIGH INCREASE
pulsos--;}
else{ //when pin 13 is LOW DECREASE
pulsos++;}
Serial.println(pulsos);
}
}
is sending to me(where the X are the number of pulses) for solving the equation and print the result .