博客
关于我
【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/

你可能感兴趣的文章
mysql常用操作
查看>>
MySQL常用日期格式转换函数、字符串函数、聚合函数详
查看>>
MySQL常见函数
查看>>
MySQL常见架构的应用
查看>>
MySQL常见的三种存储引擎(InnoDB、MyISAM、MEMORY)
查看>>
MySQL常见的三种存储引擎(InnoDB、MyISAM、MEMORY)
查看>>
MySQL常见约束条件
查看>>
MySQL常见错误
查看>>
MySQL常见错误分析与解决方法总结
查看>>
mysql并发死锁案例
查看>>
MySQL幻读:大家好,我是幻读,我今天又被解决了
查看>>
MySQL底层概述—1.InnoDB内存结构
查看>>
MySQL底层概述—2.InnoDB磁盘结构
查看>>
MySQL底层概述—3.InnoDB线程模型
查看>>
MySQL底层概述—4.InnoDB数据文件
查看>>
MySQL底层概述—5.InnoDB参数优化
查看>>
MySQL底层概述—6.索引原理
查看>>
MySQL底层概述—7.优化原则及慢查询
查看>>
MySQL底层概述—8.JOIN排序索引优化
查看>>
MySQL底层概述—9.ACID与事务
查看>>