MakeBlock Drive Updated Updated library for MakeBlock Ranger

Loading...
Searching...
No Matches
Public Member Functions | List of all members
MeCompass Class Reference

Driver for MeCompass module. More...

`#include <src/MeCompass.h>`

Inheritance diagram for MeCompass:
[legend]
Collaboration diagram for MeCompass:
[legend]

## Public Member Functions
| MeCompass ()
| MeCompass (uint8_t port)
| MeCompass (uint8_t port, uint8_t address)
void | setpin (uint8_t keyPin, uint8_t ledPin)
void | begin (void)
bool | testConnection (void)
double | getAngle (void)
int16_t | getHeadingX (void)
int16_t | getHeadingY (void)
int16_t | getHeadingZ (void)
int16_t | getHeading (int16_t *x, int16_t *y, int16_t *z)
Public Member Functions inherited from MePort
| MePort (void)
| MePort (uint8_t port)
| MePort (uint8_t port, uint8_t slot)
uint8_t | getPort (void)
uint8_t | getSlot (void)
bool | dRead1 (uint8_t mode=INPUT)
bool | dRead2 (uint8_t mode=INPUT)
bool | dpRead1 (void)
bool | dpRead2 (void)
void | dWrite1 (bool value)
void | dWrite2 (bool value)
int16_t | aRead1 (void)
int16_t | aRead2 (void)
void | aWrite1 (int16_t value)
void | aWrite2 (int16_t value)
void | reset (uint8_t port)
void | reset (uint8_t port, uint8_t slot)
uint8_t | pin1 (void)
uint8_t | pin2 (void)
uint8_t | pin (void)
uint8_t | pin (uint8_t port, uint8_t slot)

## Additional Inherited Members
Protected Attributes inherited from MePort
uint8_t | s1
uint8_t | s2
uint8_t | _port
uint8_t | _slot

## Detailed Description

Driver for MeCompass module.

Class: MeCompass

Description
  Declaration of Class MeCompass

Copyright (C), 2012-2016, MakeBlock

## Constructor & Destructor Documentation

## ◆ MeCompass() [1/3]

MeCompass::MeCompass | ( |  | ) |

Alternate Constructor which can call your own function to map the MeCompass to arduino port, no pins are used or initialized here

## ◆ MeCompass() [2/3]

MeCompass::MeCompass | ( | uint8_t | port | ) |

Alternate Constructor which can call your own function to map the MeCompass to arduino port, no pins are used or initialized here, but PWM frequency set to 976 Hz

Parameters

  [in] | port | - RJ25 port from PORT_1 to M2

## ◆ MeCompass() [3/3]

MeCompass::MeCompass | ( | uint8_t | port,
|  | uint8_t | address
| ) |  |

Alternate Constructor which can call your own function to map the MeCompass to arduino port and change the i2c device address no pins are used or initialized here, but PWM frequency set to 976 Hz

Parameters

  [in] | port | - RJ25 port from PORT_1 to M2
  [in] | address | - the i2c address you want to set

## Member Function Documentation

## ◆ begin()

void MeCompass::begin | ( | void |  | ) |

Function
  begin

Description
  Initialize the MeCompass.

Parameters

  [in] | None |

Output
  None

Returns
  None

Others
  You can check the HMC5883 datasheet for the macro definition.

## ◆ getAngle()

double MeCompass::getAngle | ( | void |  | ) |

Function
  getAngle

Description
  Calculate the yaw angle by the calibrated sensor value.

Parameters

  [in] | None |

Output
  None

Returns
  The angle value from 0 to 360 degrees. If not success, return an error code.

Others
  Will return a correct angle when you keep the MeCompass working in the plane which have calibrated.

## ◆ getHeading()

int16_t MeCompass::getHeading | ( | int16_t * | x,
|  | int16_t * | y,
|  | int16_t * | z
| ) |  |

Function
  getHeading

Description
  Get the sensor value of 3 axes including X-axis, Y-axis and Z-axis.

Parameters

  [in] | x | - the address of the variable you want to store the value in.
  [in] | y | - the address of the variable you want to store the value in.
  [in] | z | - the address of the variable you want to store the value in.

Output
  None

Returns
  If error, will return a error code, else return 0.

Others
  The sequence of the sensor data registors of HMC5883 is X, Z, Y.

## ◆ getHeadingX()

int16_t MeCompass::getHeadingX | ( | void |  | ) |

Function
  getHeadingX

Description
  Get the sensor value of X-axis.

Parameters

  [in] | None |

Output
  None

Returns
  The sensor value of X-axis. If error, will return a error code.

Others
  The sensor value is a 16 bits signed integer.

## ◆ getHeadingY()

int16_t MeCompass::getHeadingY | ( | void |  | ) |

Function
  getHeadingY

Description
  Get the sensor value of Y-axis.

Parameters

  [in] | None |

Output
  None

Returns
  The sensor value of Y-axis. If error, will return a error code.

Others
  The sensor value is a 16 bits signed integer.

## ◆ getHeadingZ()

int16_t MeCompass::getHeadingZ | ( | void |  | ) |

Function
  getHeadingZ

Description
  Get the sensor value of Z-axis.

Parameters

  [in] | None |

Output
  None

Returns
  The sensor value of Z-axis. If error, will return a error code.

Others
  The sensor value is a 16 bits signed integer.

## ◆ setpin()

void MeCompass::setpin | ( | uint8_t | keyPin,
|  | uint8_t | ledPin
| ) |  |

Function
  setpin

Description
  Set the PIN of the button module.

Parameters

  [in] | keyPin | - pin mapping for arduino
  [in] | ledPin | - pin mapping for arduino

Output
  None

Returns
  None.

Others
  Set global variable _KeyPin, _ledPin, s1 and s2

## ◆ testConnection()

bool MeCompass::testConnection | ( | void |  | ) |

Function
  testConnection

Description
  Identify the device whether is the MeCompass.

Parameters

  [in] | None |

Output
  None

Returns
  true or false

Others
  You can check the HMC5883 datasheet for the identification code.

The documentation for this class was generated from the following files:

- src/MeCompass.h
- src/MeCompass.cpp