- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在串行监视器上显示输出,但我想要将输出保存到 EEPROM。我如何循环10次并收集10个数据并将10个数据存储到EEPROM?据我了解,我需要创建一个计数器来计数到 10。我需要为我的变量使用数组吗?还有一个 while 循环,我对吗?
编辑:我指的是ARDUINO
这是代码。我正在使用旧的加速度计代码。正如你所看到的,代码存储在之前的 X、Y、Z 轴和 g 级别中。但现在我想存储速度和距离的值。使用while循环让输出运行10次然后将其存储到EEPROM。
#include <math.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#define O0 11
#define O1 10
#define O2 9
#define O3 6
#define O4 5
#define O5 3
#define I0 A0
#define I1 A1
#define I2 A2
#define I3 A3
#define I4 A4
#define I5 A5
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin1 = I0; // Analog input pin that the Accelerometer's first pin is attached to
const int analogInPin2 = I1; // Analog input pin that the Accelerometer's second pin is attached to
const int analogInPin3 = I2; // z-axis
const float LPF_alpha = 0.16; //LPF_Alpha=dT/(RC+dT)
const float HPF_alpha = 0.83; //HPF_Alpha=RC/(RC+dT)
const float gNlowB=0.038,GNlowB=0.008;
const float gNhighB=1,GNhighB=1;
float ValueX,ValueY,ValueZ; //raw data from ADC
//acc date wrt to g value of earth, gN is the norm
//gNavg is after LPF (the constant due to earth). gNins should be 0 if not moving...
//these data do averaging on individual axis
float gX,gY,gZ,gXA,gYA,gZA,gXP,gYP,gZP;
float gXins,gYins,gZins,gNins,gXinsP,gYinsP,gZinsP,gNinsP;
float gXinsA=0,gYinsA=0,gZinsA=0,gNinsA=0;
float GN,GNP,GNA,GNins,GNinsA=0;
float gNinsMax,GNinsMax;
float actgN_acc=0,actGN_acc=0;
float actgN,actGN;
float act_dist=0,act_DIST=0;
float gX_hpf=0,gY_hpf=0,gZ_hpf=0,GN_hpf=0;
//these data convert to norm early on, and do avg/ins
float gN_hpf=0;
float vel=0, dist=0, VEL=0,DIST=0;
float aX, aY, aZ; //tilt angle
float vdd=4.91; //the measured 5V supply. Meter reading is more accurate
//sensitivity from datasheet is 0.5V/g. unit of sens is g/value. 1024=vdd
//this group of data can be calibrated and stored in EEPROM
float sens=(vdd/1024)/0.5000;
float sensX=sens; //without calibration, default value is from the datasheet
float sensY=sens;
float sensZ=sens;
float mid=1023/2;
float midX=mid;
float midY=mid;
float midZ=mid;
unsigned long time,preTime=0,curTime; //dT need for integration
float dT=0,aT=0;
int noAvg=10; //averaging of 10 reading
int dispCnt=1,actCnt=0; //display 1/10 the data or else human can't read. actCnt must be offset from dispCnt
int keyResponse;
struct calData_t
{ int written; //99 if written
float mx,my,mz,sx,sy,sz;
} ;
calData_t calData;
struct gVector_t{
float gx,gy,gz;
};
gVector_t gV,gVNorm;
float readAcc(float &ValueX,float &ValueY, float &ValueZ, char One, int noAvg);
void calOne(char One, float &mid, float &sens);
void LPF(float &d, float &dAvg, float &dIns); //LPF 1 data
void Max(float &Max, float &d);
void reset_vel(float &a, float lowB, float &v);
int readkey() {
// read 1 char from serial monitor
int c;
while(!Serial.available());
c= Serial.read(); //read 1 byte only read 1 byte
delay(100);
while(Serial.available()>0){
Serial.read(); //keeping reading. Clear the buffer until Serial.available()==0
}
return c;
}
void calibration(){
calOne('z',midZ,sensZ);
calOne('x',midX,sensX);
calOne('y',midY,sensY);
dispCalData();
storeCalData();
}
void storeCalData(){
calData=(calData_t){99 , midX,midY,midZ,sensX,sensY,sensZ};
while (!eeprom_is_ready()); // Wait for EEPROM to be ready
cli();
eeprom_write_block((const void*)&calData, (void*)0, sizeof(calData));
Serial.println("Cal data written to EEPROM...");
sei();
}
void dispCalData(){
Serial.println("The current middle value and sensitivity are: ");
Serial.print("sensX:");
Serial.print(sensX,5);
Serial.print("\tsensY:");
Serial.print(sensY,5);
Serial.print("\tsensZ");
Serial.print(sensZ,5);
Serial.print("\tsens without cal:");
Serial.println(sens,5);
Serial.print("midX:");
Serial.print(midX,5);
Serial.print("\tmidY:");
Serial.print(midY,5);
Serial.print("\tmidZ");
Serial.print(midZ,5);
Serial.print("\tmid without cal:");
Serial.println(mid,5);
delay(5000);
}
void calOne(char One, float &mid, float &sens){
//when you're cal z=+1g, you could cal for x=y=0g
//this only need to perfm 6 cal instead of 9 cal
//however, it is more messy in the code and hard to trace if there is cal error.
float Pos1g=0, Neg1g=0;
String String1=String(One)+"=0g cal: put "+String(One)+ "=0g and hit 'y' & RETURN";
String String2=String(One)+"=+1g cal: put +"+String(One)+ " facing upwards and hit 'y' & RETURN";
String String3=String(One)+"=-1g cal: put +"+String(One)+ " facing downwards and hit 'y' & RETURN";
Serial.println(String1);
keyResponse=readkey();
if (keyResponse=='y'){
delay(1000);
mid=readAcc(ValueX,ValueY,ValueZ,One,100);
}
Serial.println(String2);
keyResponse=readkey();
if (keyResponse=='y'){
delay(1000);
Neg1g=readAcc(ValueX,ValueY,ValueZ,One, 100);
}
Serial.println(String3);
keyResponse=readkey();
if (keyResponse=='y'){
delay(1000);
Pos1g=readAcc(ValueX,ValueY,ValueZ,One,100);
}
if (Pos1g==0 || Neg1g==0){}
else {sens=2/(Pos1g-Neg1g);}
}
float readAcc(float &ValueX,float &ValueY, float &ValueZ, char One, int noAvg){
//read acc data (from ADC) with averaging. Return values via pointers.
//parameter One allow you to return 1 axis acc reading.
float X=0; float Y=0; float Z=0;
for (int i=0; i < noAvg; i++){ //int is 16bit
X = X+analogRead(analogInPin1);
Y = Y+analogRead(analogInPin2);
Z = Z+analogRead(analogInPin3);
delay(10); //datasheet suggest 10ms delay for ADC to settle
}
ValueX=X/noAvg;
ValueY=Y/noAvg;
ValueZ=Z/noAvg;
if (One == 'x') { return ValueX;}
else if (One == 'y'){ return ValueY;}
else { return ValueZ;}
}
void Max(float &Max, float &d){ //max is keyword
if (d>Max){Max=d;}
}
void cap(float &d,float lowB, float highB){
if (d<lowB){d=0;}
else if (d>highB){d=highB;}
else {;}
}
void reset_vel(float &a, float lowB, float &v){
if (a<lowB){v=0;}
}
float mapAcc(float x, float mid, float sens){
//what return is the actual acc data in g
return sens*(x-mid);
}
float norm(float x, float y, float z){
return sqrt(x*x+y*y+z*z);
}
void LPF(float &gN, float &gNP, float &gNA, float &gNins){
gNA=LPF_alpha*gN + (1-LPF_alpha)*gNA;
gNins=gN-gNA;
}
void HPF(float &gin, float &ginP, float &gout){
gout=HPF_alpha*(gout+gin-ginP);
}
void display_result(int delayLoop){
delay(delayLoop);
Serial.print(" gXins=" );
Serial.print(gXins,5);
Serial.print(" gYins=" );
Serial.print(gYins,5);
Serial.print(" gZins=" );
Serial.print(gZins,5);
Serial.print(" gNins=" );
Serial.print(gNins,5);
Serial.print(" gXinsA=" );
Serial.print(gXinsA*1e3,5);
Serial.print(" gYinsA=" );
Serial.print(gYinsA*1e3,5);
Serial.print(" gZinsA=" );
Serial.print(gZinsA*1e3,5);
Serial.print(" gNinsA=" );
Serial.print(gNinsA*1e3,5);
Serial.print('\n');
Serial.print(" gNins=" );
Serial.print(gNins,5);
Serial.print(" GNins=" );
Serial.print(GNins,5);
Serial.print(" gNinsA=" );
Serial.print(gNinsA,5);
Serial.print(" GNinsA=" );
Serial.print(GNinsA,5);
Serial.print(" gNinsMax=" );
Serial.print(gNinsMax,5);
Serial.print(" GNinsMax=" );
Serial.print(GNinsMax,5);
Serial.print("\n");
Serial.print(" aT=" );
Serial.print(aT/1e6);
Serial.print(" dT=" );
Serial.print(dT/1000,3);
Serial.print(" dispCnt=" );
Serial.print(dispCnt);
Serial.print(" actCnt=" );
Serial.print(actCnt);
Serial.print("\n");
Serial.print(" vel=" );
Serial.print(vel,3);
Serial.print(" VEL=" );
Serial.print(VEL,3);
Serial.print(" dist=" );
Serial.print(dist,3);
Serial.print(" DIST=" );
Serial.print(DIST,3);
Serial.print(" actgN=" );
Serial.print(actgN,3);
Serial.print(" actGN=" );
Serial.print(actGN,3);
Serial.print(" act_dist=" );
Serial.print(act_dist,3);
Serial.print(" act_DIST=" );
Serial.print(act_DIST,3);
Serial.println(' ');
Serial.print("\n");
}
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Serial.println("Hit 'y' and RETURN, if you want to calibrate...");
Serial.println("Hit 'x' and RETURN, if you want to clear the cal data in EEPROM...");
Serial.println("If not, 'n' and RETURN");
//keyResponse=readkey();
keyResponse='n';
if (keyResponse=='y'){
calibration();
}
else if (keyResponse=='x'){
while (!eeprom_is_ready()); // Wait for EEPROM to be ready
cli();
calData.written=0;
eeprom_write_block((const void*)&calData, (void*)0, sizeof(calData));
Serial.println("Cal data is cleared...");
sei();
}
else {
while (!eeprom_is_ready()); // Wait for EEPROM to be ready
cli();
eeprom_read_block((void*)&calData, (void*)0, sizeof(calData));
sei();
if (calData.written==99){
Serial.println("Using previously stored cal data from EEPROM");
midX=calData.mx; midY=calData.my; midZ=calData.mz;
sensX=calData.sx;sensY=calData.sy;sensZ=calData.sz;
}
else {
Serial.println("no previous cal data, using default");
}
dispCalData();
}
readAcc(ValueX,ValueY,ValueZ,'x',10);
gXA = mapAcc(ValueX, midX, sensX); //cannot let gXA at 0, will create err.
gYA = mapAcc(ValueY, midY, sensY);
gZA = mapAcc(ValueZ, midZ, sensZ);
GNA = norm(gXA,gYA,gZA);
preTime=micros();
}
void loop() {
// read the both analog in values:
readAcc(ValueX,ValueY,ValueZ,'x',10);
curTime=micros();
dT=curTime-preTime;
preTime=curTime;
aT=aT+dT;
gX = mapAcc(ValueX, midX, sensX);
gY = mapAcc(ValueY, midY, sensY);
gZ = mapAcc(ValueZ, midZ, sensZ);
LPF(gX,gXP,gXA,gXins);
LPF(gY,gYP,gYA,gYins);
LPF(gZ,gZP,gZA,gZins);
gNins=norm(gXins,gYins,gZins);
cap(gNins,0.01,1);
gXinsA=(gXinsA+gXins)/2;
gYinsA=(gYinsA+gYins)/2;
gZinsA=(gZinsA+gZins)/2;
gNinsA=(gNinsA+gNins)/2;
GN = norm(gX,gY,gZ);
LPF(GN,GNP,GNA,GNins);
cap(GNins,GNlowB,GNhighB);
GNinsA=(GNinsA+GNins)/2;
Max(gNinsMax,gNins);
Max(GNinsMax,GNins);
reset_vel(gNins, gNlowB, vel);
reset_vel(GNins, GNlowB, VEL);
vel=vel+9.81e-6*gNins*dT;
VEL=VEL+9.81e-6*GNins*dT;
act_dist=act_dist+9.81e-6*vel*dT;
act_DIST=act_DIST+9.81e-6*VEL*dT;
actCnt=actCnt+1;
if (actCnt>=10){
actGN=sqrt(actGN_acc/10);
actGN_acc=0;
actgN=sqrt(actgN_acc/10);
actgN_acc=0;
dist=dist+act_dist; act_dist=0;
DIST=DIST+act_DIST; act_DIST=0;
actCnt=0;
}
actgN_acc=actgN_acc+(gNins*gNins);
actGN_acc=actGN_acc+(GNins*GNins);
// print the results to the serial monitor:
dispCnt=dispCnt+1;
if (dispCnt>=40){
display_result(0);
dispCnt=0;
}
gXP=gX; gYP=gY; gZP=gZ; GNP=GN;
}
最佳答案
我假设你想要这样的东西
#define MAX_VAL 10
int arrvalues[MAX_VAL] = {0,10,20,30,40,50,60,70,80,90};
现在你可以像使用for..loop
一样编写
int i;
for ( i = 0; i < MAX_VAL ; ++i )
EEPROM.write ( i, arrvalues[ i ] );
使用while...循环
int i=0;
while(i<MAX_VAL){
EEPROM.write ( i, arrvalues[ i ] );
i++;
}
关于收集数据并将其存储到 EEPROM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25033308/
我正在运行一个辅助角色,并检查 Azure 上托管的存储中是否存在数据。当我将连接字符串用于经典类型的存储时,我的代码可以正常工作,但是当我连接到 V2 Azure 存储时,它会抛出此异常。 “远程服
在我的应用程序的主页上,我正在进行 AJAX 调用以获取应用程序各个部分所需的大量数据。该调用如下所示: var url = "/Taxonomy/GetTaxonomyList/" $.getJSO
大家好,我正在尝试将我的商店导入我的 Vuex Route-Gard。 路由器/auth-guard.js import {store} from '../store' export default
我正在使用 C# 控制台应用程序 (.NET Core 3.1) 从 Azure Blob 存储读取大量图像文件并生成这些图像的缩略图。新图像将保存回 Azure,并将 Blob ID 存储在我们的数
我想将 Mlflow 设置为具有以下组件: 后端存储(本地):在本地使用 SQLite 数据库存储 Mlflow 实体(run_id、params、metrics...) 工件存储(远程):使用 Az
我正在使用 C# 控制台应用程序 (.NET Core 3.1) 从 Azure Blob 存储读取大量图像文件并生成这些图像的缩略图。新图像将保存回 Azure,并将 Blob ID 存储在我们的数
我想将 Mlflow 设置为具有以下组件: 后端存储(本地):在本地使用 SQLite 数据库存储 Mlflow 实体(run_id、params、metrics...) 工件存储(远程):使用 Az
我的 Windows 计算机上的本地文件夹中有一些图像。我想将所有图像上传到同一容器中的同一 blob。 我知道如何使用 Azure Storage SDKs 上传单个文件BlockBlobServi
我尝试发出 GET 请求来获取我的 Azure Blob 存储帐户的帐户详细信息,但每次都显示身份验证失败。谁能判断形成的 header 或签名字符串是否正确或是否存在其他问题? 代码如下: cons
这是用于编写 JSON 的 NeutralinoJS 存储 API。是否可以更新 JSON 文件(推送数据),而不仅仅是用新的 JS 对象覆盖数据。怎么做到的??? // Javascript
我有一个并行阶段设置,想知道是否可以在嵌套阶段之前运行脚本,所以像这样: stage('E2E-PR-CYPRESS') { when { allOf {
我想从命令行而不是从GUI列出VirtualBox VM的详细信息。我对存储细节特别感兴趣。 当我在GUI中单击VM时,可以看到包括存储部分在内的详细信息: 但是到目前为止,我还没有找到通过命令行执行
我有大约 3500 个防洪设施,我想将它们表示为一个网络来确定流动路径(本质上是一个有向图)。我目前正在使用 SqlServer 和 CTE 来递归检查所有节点及其上游组件,只要上游路径没有 fork
谁能告诉我 jquery data() 在哪里存储数据以及何时删除以及如何删除? 如果我用它来存储ajax调用结果,会有性能问题吗? 例如: $("body").data("test", { myDa
有人可以建议如何为 Firebase 存储中的文件设置备份。我能够备份数据库,但不确定如何为 firebase 存储中的文件(我有图像)设置定期备份。 最佳答案 如何进行 Firebase 存储的本地
我最近开始使用 firebase 存储和 firebase 功能。现在我一直在开发从功能到存储的文件上传。 我已经让它工作了(上传完成并且文件出现在存储部分),但是,图像永远保持这样(永远在右侧加载)
我想只允许用户将文件上传到他们自己的存储桶中,最大文件大小为 1MB,仍然允许他们删除文件。我添加了以下内容: match /myusers/{userId}/{allPaths=**} { al
使用生命周期管理策略将容器的内容从冷访问层移动到存档。我正在尝试以下策略,希望它能在一天后将该容器中的所有文件移动到存档层,但事实并非如此在职的。我设置了选择标准“一天未使用后”。 这是 json 代
对于连接到 Azure 存储端点,有 http 和 https 两个选项。 第一。 https 会带来开销,可能是 5%-10%,但我不支付同一个数据中心的费用。 第二。 http 更快,但 Auth
有人可以帮我理解这一点吗?我创建了Virtual Machine in Azure running Windows Server 2012 。我注意到 Azure 自动创建了一个存储帐户。当我进入该存
我是一名优秀的程序员,十分优秀!