arduino I2C传感器及1602液晶显示屏,void变量值带入loop循环的问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arduino I2C传感器及1602液晶显示屏,void变量值带入loop循环的问题相关的知识,希望对你有一定的参考价值。
Arduino2560, 想把heading_o的初始值通过指针TT带入到loop循环, 作为一个不变的参照值, 但实际带过来的值却不停的在变化, 且并不是初始值,不知道问题出在哪里, 请大侠指点:
#include <Wire.h>
#include <HMC5883L.h>
#include <math.h>
#include <LiquidCrystal_I2C.h>
HMC5883L compass;
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display
float *TT;
void setup()
Serial.begin(9600);
Wire.begin();
compass = HMC5883L();
compass.SetScale(1.3);
compass.SetMeasurementMode(Measurement_Continuous);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.print("Hello, world!");
delay(3000);
MagnetometerRaw raw = compass.ReadRawAxis();
MagnetometerScaled scaled = compass.ReadScaledAxis();
float xHeading = atan2(scaled.YAxis, scaled.XAxis);
if(xHeading < 0) xHeading += 2*PI;
if(xHeading > 2*PI) xHeading -= 2*PI;
float heading_o;
heading_o1 = xHeading * 180/M_PI-180;
TT=&heading_o;
lcd.setCursor(8,0);
lcd.print(heading_o);
delay(3000);
void loop()
MagnetometerRaw raw = compass.ReadRawAxis();
MagnetometerScaled scaled = compass.ReadScaledAxis();
float xHeading = atan2(scaled.YAxis, scaled.XAxis);
if(xHeading < 0) xHeading += 2*PI;
if(xHeading > 2*PI) xHeading -= 2*PI;
float xDegrees = xHeading * 180/M_PI;
float heading = xDegrees-180;
Serial.print(xDegrees);
Serial.print(",");
Serial.println(";");
Serial.print(heading);
Serial.println(";____");
lcd.clear();
lcd.print(xDegrees);
lcd.setCursor(8,0);
lcd.print(*TT);
lcd.setCursor(0,1);
lcd.print(heading);
Arduino怎么样使用串行1602液晶
参考技术A 串行1602液晶是通过串口接收数据来显示的,而想要简洁明了的与Arduino控制器相连就需要一块传感器扩展版,因为传感器扩展板上预留有与之插接的COM口。硬件连接后,只要在程序中编写串口发送的程序即可。以上是关于arduino I2C传感器及1602液晶显示屏,void变量值带入loop循环的问题的主要内容,如果未能解决你的问题,请参考以下文章
Arduino UNO与超声波传感器接口进行测距,将距离显示在LCD1602液晶屏上,第一行?
我用arduino做的超声波测距,现在想把测到的距离用lcd1602液晶显示屏显示出来,该怎么做,