Demo example on FRDM-64F https://ide.mbed.com/compiler/#nav:/rzr-example-mbed;

Dependencies:   FXOS8700Q

main.cpp

Committer:
rzrfreefr
Date:
12 months ago
Revision:
0:16519bf92477

File content as of revision 0:16519bf92477:

/// SPDX-License-Indentifier: MPL-2.0
/// Copyright: 2020+ Philippe Coval <https://purl.org/rzr>

#include "mbed.h"

#include "EthernetInterface.h"
#include "USBKeyboard.h"
#include "FXOS8700Q.h"

#define USB_ENABLED 1
#define NET_ENABLED 1

int main()
{
  printf("%s\n", __FILE__);
  I2C i2c(PTE25, PTE24);
  motion_data_units_t acc_data;
  motion_data_counts_t acc_raw;

  FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
#ifdef USB_ENABLED
  printf("usb:\n");
  USBKeyboard usb; ///< https://os.mbed.com/docs/mbed-os/v6.2/apis/usbkeyboard.html
#endif

#ifdef NET_ENABLED
  EthernetInterface eth; ///< https://os.mbed.com/docs/mbed-os/v6.2/apis/ethernet.html
  eth.set_dhcp(true);
  eth.connect();
#endif
    
  DigitalOut led(LED1);

  int16_t rmX, rmY, rmZ;
  acc.enable();
  printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
  while (true) {
    acc.getAxis(acc_data);
    printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f  ", acc_data.x, acc_data.y, acc_data.z);
    printf("%s\n", __FILE__);
    led = !led;
#ifdef NET_ENABLED
    printf("\nClient IP Address is %s\n", eth.get_mac_address());        
    SocketAddress a;
    eth.get_ip_address(&a);
    printf("IP address: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
#endif
#ifdef USB_ENABLED
    usb.connect();
    usb.printf("# \n");
#endif
    ThisThread::sleep_for(1000.f);
  }
}