博客
关于我
【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 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>