2 لایک
-
این برنامه قطب نما "نمایش زاویه بر روی lcd5110
/*
# pin 7 - Serial clock out (SCLK)
# pin 6 - Serial data out (DIN)
# pin 5 - Data/Command select (D/C)
# pin 4 - LCD chip select (CS)
# pin 3 - LCD reset (RST)
*/
#include <LCD_GFX.h>
#include <NOKIA5110.h>
NOKIA5110 display = NOKIA5110(7, 6, 5, 4, 3);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup() {
Serial.begin(9600);
display.begin();
display.clearDisplay();
display.setContrast(50);
Wire.begin();
display.setTextSize(2);
display.setCursor(9,7);
display.println("TANHA");
display.setTextSize(1);
display.setCursor(7,40);
display.println("HABIB MORADI");
display.display();
delay(3000);
display.clearDisplay();
compass = HMC5883L(); //new instance of HMC5883L library
setupHMC5883L(); //setup the HMC5883L
}
void loop() {
display.setTextSize(1);
display.setTextColor(BLACK);// 2 C
display.setCursor(1,1);
display.println("SCANING...");
display.setTextSize(1);
display.setCursor(7,40);
display.println("www.daba.ir");
display.begin();
delay(100);
display.setContrast(50);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(10,20);
float heading = getHeading();
display.println(heading);
delay(500); //only here to slow down the serial print
}
void setupHMC5883L(){
//Setup the HMC5883L, and check for errors
int error;
error = compass.SetScale(1.3); //Set the scale of the compass.
if(error != 0) display.println(compass.GetErrorText(error)); //check if there is an error, and print if so
error = compass.SetMeasurementMode(Measurement_Continuous) ; // Set the measurement mode to Continuous
if(error != 0) display.println(compass.GetErrorText(error)); //check if there is an error, and print if so
}
float getHeading(){
//Get the reading from the HMC5883L and calculate the heading
MagnetometerScaled scaled = compass.ReadScaledAxis(); //scaled values from compass.
float heading = atan2(scaled.YAxis, scaled.XAxis);
// Correct for when signs are reversed.
if(heading < 0) heading += 2*PI;
if(heading > 2*PI) heading -= 2*PI;
return heading * RAD_TO_DEG; //radians to degrees
display.display();
}
مجوز های ارسال و ویرایش
- شما نمیتوانید موضوع جدیدی ارسال کنید
- شما امکان ارسال پاسخ را ندارید
- شما نمیتوانید فایل پیوست کنید.
- شما نمیتوانید پست های خود را ویرایش کنید
-
مشاهده قوانین انجمن
SEO by vBSEO