Loading...
Processing Forum
Recent Topics
All Forums
Move this topic
Forum :
Share your Work
Programming Questions
Core Library Questions
Contributed Library Questions
Android Processing
Processing with Other Languages
Integration and Hardware
Library and Tool Development
Events and Opportunities
General Discussion
Sub forum :
Move this topic
Cancel
General Discussion
Other
claire23
Placing the average of serial readings over a period of time into a float...
in
General Discussion
•
Other
•
5 months ago
Is it possible to take, for instance, the serial readings over a period of 5 seconds and divide that by 5 to get the average... then stick that average number into a float?
1
Replies(3)
PhiLho
Re: Placing the average of serial readings over a period of time into a float...
5 months ago
Well, sure, it is totally possible.
Leave a comment on PhiLho's reply
v.k.
Re: Placing the average of serial readings over a period of time into a float...
5 months ago
It would look some thing like:
(Simulating reads avery second with a random number)
int time;
float[] reads = new float[5];
int last;
void setup(){
time = millis();
}
void draw(){
if (last == reads.length){
float total = 0.0;
for (int i = 0; i< reads.length; i++){
total = total + reads[i]; // adds all together
}
println("reads stored are : ");
println(reads);
print("that adds up to:");
println(total);
println("averaging : " + total/5f + "\n"); // average is done here
//reset position counter
last = 0;
}
// simulating input and adding to storage
if (millis() - time > 1000){
reads[last] = random(1);
time = millis();
// increment storage position
last++;
}
}
Leave a comment on v.k.'s reply
claire23
Re: Placing the average of serial readings over a period of time into a float...
5 months ago
Thank you!
Leave a comment on claire23's reply
Change topic type
Topic Type :
Discussions
Questions
No of days :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to claire23's question
Top
Reply
{"z26740330":[25080000002144592,25080000002145773],"z4085862":[25080000002144707],"z4289448":[25080000002144817]}
Statistics
3
Replies
365
Views
0
Followers
Tags
No tags available for this topic.
Cancel
Actions
Permalink
Related Posts
128.9 + 0.2 = 129.09999 ??? - Is th...
Current time to Unix Timestamp / Ep...
Is it possible to store a large num...
Autoscaling Processing plot
3d model bouncing randomly - seekin...