int pot = A0;
int value;
float v[4]={0.0};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(pot,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
value = analogRead(pot);
float x = float(value)*5/1024;
v[0] = v[1];
v[1] = v[2];
v[2] = v[3];
v[3] = v[4];
v[4] = (5.410813636231793788e-1 * x)
+ (-0.49297369305844135345 * v[0])
+ (0.10136107908629476970 * v[1])
+ (0.59665868765467522383 * v[2])
+ (0.45077979658470224145 * v[3]);
float D = v[4]-v[3];
delay(100);
Serial.println(x);
Serial.print(" ");
Serial.print(v[4]);
Serial.print(" ");
Serial.println(D);
}
// I used this code to filter the signal but after adding delay it is not doing serial plotting or serial monitoring. Please give your valuable suggestions.
Your topic was MOVED to its current forum category as it is more suitable than the original
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
1 Like
vikas0845:
float v[4]={0.0};
vikas0845:
float D = v[4]-v[3];
You have defined an array with 4 values. The indices of those values is 0,1,2, and 3.
v[4] is out of range.
The program is crashing and constantly restarting. Put some more print statements in setup to see this.
Also.. floats have about 6-7 digits of precision.
vikas0845:
-0.49297369305844135345
You're dreaming using values like this.
Now, I have corrected it and wrote: float v[3] = {0.0};
Now you have an array that can hold only 3 values with index values 0, 1 and 2
How are you accessing the array ?
So you've defined an even smaller array ???
I think by v[3] = {0.0} will initialize v[0], v[1], v[2], v[3] as zero.
Then you are wrong. It will allocate space to 3 array elements numbered 0, 1 and 2 and initialise them to zero
vikas0845:
I think..
Better to read the man page
or take a view here to get some ideas:
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
vikas0845:
I think by v[3]
The point is this array holds 3 (THREE) values.
In your code you are trying to access 5 (FIVE ) values.
Computer will say NO to this.
system
Closed
December 15, 2022, 7:30am
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.