arduino I2C传感器及1602液晶显示屏,void变量值带入loop循环的问题
Arduino2560,想把heading_o的初始值通过指针TT带入到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); 展开
#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); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询