首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HC12传输传感

HC12传输传感
EN

Stack Overflow用户
提问于 2022-03-29 00:14:54
回答 1查看 42关注 0票数 -1

我是arduino的新手,我用加速度计来测量移动火箭上的加速度。我正在使用HC12无线发送器来做这件事。

我想要做的是,只有当z轴加速度发生一定变化时,才开始通过HC12发射机将数据发送到计算机。

我不知道如何处理我所做的将x、y、z和数据的值传递到函数Hc12中的函数。

这个Hc12函数仅意味着每30秒运行一次,而循环函数应该每秒运行3次。

任何帮助都将不胜感激。我的代码如下:

代码语言:javascript
复制
#include <SoftwareSerial.h>

SoftwareSerial HC12(7,6);

//initialising variables and functions
const int numReadings = 15;
int readings[numReadings];
int index = 0;
float total = 0;
int inputPin = A1;

float test;

const int numReadings1 = 15;
int readings1[numReadings1];
int index1 = 0;
float total1 = 0;
int inputPin1 = A2;

const int numReadings2 = 15;
int readings2[numReadings2];
int index2 = 0;
float total2 = 0;
int inputPin2 = A3;

float x;
float y;
float z;

void setup(){
 Serial.begin(115200);

 if ((readings2[index2]-readings2[index2-1])>0.5){
  HC12.begin(115200);
 }
 
 for (int thisReading = 0; thisReading < numReadings; thisReading++)
 readings[thisReading] = 0;

}

float Hc12(float x, float y, float z, float data)
{
  float test;
  readings2[index2] =analogRead(inputPin2);
test =readings2[index2]-readings2[index2-1];

if ((test)>0.1){

      HC12.println(data); 
}//send data
return test;
 delay(30000);
}
 
void loop() {

//x moving avg
  total = total-readings[index];
  readings[index] =analogRead(inputPin);
  total = total +readings[index];
  index = index + 1;

  if (index>=numReadings)
  index = 0;

  x = total/numReadings;

  //y moving avg
  
  total1 = total1-readings1[index1];
  readings1[index1] =analogRead(inputPin1);
  total1 = total1 +readings1[index1];
  index1 = index1 + 1;

  if (index1>=numReadings1)
  index1 = 0;

  y = total1/numReadings1;

  //z moving avg
  
  total2 = total2-readings2[index2];
  readings2[index2] =analogRead(inputPin2);
  total2 = total2 +readings2[index2];
  index2 = index2 + 1;

  if (index2>=numReadings2)
  index2 = 0;

  z = total2/numReadings2;

   //z moving avg
  
  total2 = total2-readings2[index2];
  readings2[index2] =analogRead(inputPin2);
  total2 = total2 +readings2[index2];
  index2 = index2 + 1;

  if (index2>=numReadings2)
  index2 = 0;

  z = total2/numReadings2;


String data = "";
data = data + x + "," + y + "," + z ;
 
  
 delay(30);
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-29 08:22:29

您没有调用下面的函数。还是我漏掉了一些要点?

代码语言:javascript
复制
float Hc12(float x, float y, float z, float data)

顺便说一下,我没有检查剩下的代码是否有其他错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71655068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档