Download Library
PROGRAM KOMPAS DENGAN LIBRARY
#include "Wire.h"
#include "CMPS03.h"
CMPS03 cmps03;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
Serial.println(cmps03.read());
delay(1000);
}
PROGRAM KOMPAS TANPA LIBRARY
#include <Wire.h>
#define address 0x60
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
byte highByte;
byte lowByte;
Wire.beginTransmission (address);
Wire.send(2);
Wire.endTransmission();
Wire.requestFrom(address, 2);
while(Wire.available() < 2);
highByte=Wire.receive();
lowByte=Wire.receive();
float bearing=(highByte<<8)+lowByte);
bearing = bearing/10;
Serial.print(bearing);
Serial.print("\xB0\t");// penampilan karakter derajat
Serial.println(); //enter
delay(100);
}
1 comments:
Click here for commentsgan, bagaimana ya caranya mengatasi posisi lapangan yang diputar pada lapangan krci jika robotnya memakai kompas?
ConversionConversion EmoticonEmoticon