博客
关于我
【3/10】 基于arduino的算数…
阅读量:330 次
发布时间:2019-03-04

本文共 762 字,大约阅读时间需要 2 分钟。

简介:
算数平均滤波法简单有效,可用于上下变跳波动较小的数据,不适合拥有大范围跳变的讯号。
const int Input = 1;//A1为电平输入口
const int Output = 0;//A0为电平输出口
const int savenum = 3;//每次存储多少个数
int OriginValue[savenum];//数组存储输入的电平大小
double AveValue = 0;//算数平均后得到的数值
int Acount = 0;//计数器
void setup() {
 
// put your setup code here, to run once:
 
Serial.begin(9600);
 
 
}
void Receive()//将输入模拟信号存储到数组的函数
{
 
 
 
if (Acount
 
{
 
 
 
OriginValue[Acount] = analogRead(Input);
 
 
 
Acount++;
 
}
 
else
 
{
 
 
 
Acount= 0;
 
 
 
Average();
 
}
}
void Average()//求平均值的函数
{
 
int count;
 
double Sum;
 
for(count=0;count
 
Sum += (double)(OriginValue[count]);
 
AveValue = Sum / savenum;
 
SignalOut();
}
void SignalOut()//输出信号的函数
{
 
analogWrite(Output,AveValue);//每次求平均值后输出
 
Serial.println(AveValue);
}
void loop() {
 
// put your main code here, to run repeatedly:
 
Receive();
 
}

转载地址:http://jtyh.baihongyu.com/

你可能感兴趣的文章
Netty 异步任务调度与异步线程池
查看>>
Netty 的 Handler 链调用机制
查看>>
Netty 编解码器详解
查看>>
Netty 解决TCP粘包/半包使用
查看>>
Netty 调用,效率这么低还用啥?
查看>>
Netty 高性能架构设计
查看>>
Netty+Protostuff实现单机压测秒级接收35万个对象实践经验分享
查看>>
Netty+SpringBoot+FastDFS+Html5实现聊天App详解(一)
查看>>
netty--helloword程序
查看>>
Netty5.x 和3.x、4.x的区别及注意事项(官方翻译)
查看>>
netty——bytebuf的创建、内存分配与池化、组成、扩容规则、写入读取、内存回收、零拷贝
查看>>
netty——Channl的常用方法、ChannelFuture、CloseFuture
查看>>
netty——EventLoop概念、处理普通任务定时任务、处理io事件、EventLoopGroup
查看>>
netty——Future和Promise的使用 线程间的通信
查看>>
netty——Handler和pipeline
查看>>
Vue输出HTML
查看>>
netty——黏包半包的解决方案、滑动窗口的概念
查看>>
Netty中Http客户端、服务端的编解码器
查看>>
Netty中使用WebSocket实现服务端与客户端的长连接通信发送消息
查看>>
Netty中实现多客户端连接与通信-以实现聊天室群聊功能为例(附代码下载)
查看>>