Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ESDC2014 by
compass.cpp
- Committer:
- terryLAI
- Date:
- 2014-07-03
- Revision:
- 1:cbec1283a16a
- Parent:
- 0:3417ca0a36c0
- Child:
- 2:442902ec3aa1
File content as of revision 1:cbec1283a16a:
#include "compass.h"
COMPASS::COMPASS(PinName tx, PinName rx)
{
this->serial= new MySerial(tx,rx);
serial->baud(56000);
serial->format(8,SerialBase::None, 1);
init();
}
uint16_t COMPASS::Read()
{
resume();
buffer[0]=serial->getc();
buffer[1]=serial->getc();
stop();
degree=(uint8_t)(buffer[0])*256+(uint8_t)(buffer[1]);
return degree;
}
void COMPASS::init()
{
run();
stop();
}
void COMPASS::run()
{
write2Bytes(RUN_MSB,RUN_LSB);
}
void COMPASS::stop()
{
write2Bytes(STOP_MSB,STOP_LSB);
}
void COMPASS::resume()
{
write2Bytes(RESUME_MSB,RESUME_LSB);
}
void COMPASS::reset()
{
write2Bytes(RST_MSB,RST_LSB);
}
void COMPASS::write2Bytes(char msb, char lsb)
{
serial->putc(msb);
serial->putc(lsb);
}
