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

Dependencies:   FXOS8700Q

Committer:
rzrfreefr
Date:
Wed Sep 16 14:58:57 2020 +0000
Revision:
0:16519bf92477
Initial import ; ; Source: https://ide.mbed.com/compiler/#nav:/rzr-example-mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rzrfreefr 0:16519bf92477 1 /// SPDX-License-Indentifier: MPL-2.0
rzrfreefr 0:16519bf92477 2 /// Copyright: 2020+ Philippe Coval <https://purl.org/rzr>
rzrfreefr 0:16519bf92477 3
rzrfreefr 0:16519bf92477 4 #include "mbed.h"
rzrfreefr 0:16519bf92477 5
rzrfreefr 0:16519bf92477 6 #include "EthernetInterface.h"
rzrfreefr 0:16519bf92477 7 #include "USBKeyboard.h"
rzrfreefr 0:16519bf92477 8 #include "FXOS8700Q.h"
rzrfreefr 0:16519bf92477 9
rzrfreefr 0:16519bf92477 10 #define USB_ENABLED 1
rzrfreefr 0:16519bf92477 11 #define NET_ENABLED 1
rzrfreefr 0:16519bf92477 12
rzrfreefr 0:16519bf92477 13 int main()
rzrfreefr 0:16519bf92477 14 {
rzrfreefr 0:16519bf92477 15 printf("%s\n", __FILE__);
rzrfreefr 0:16519bf92477 16 I2C i2c(PTE25, PTE24);
rzrfreefr 0:16519bf92477 17 motion_data_units_t acc_data;
rzrfreefr 0:16519bf92477 18 motion_data_counts_t acc_raw;
rzrfreefr 0:16519bf92477 19
rzrfreefr 0:16519bf92477 20 FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
rzrfreefr 0:16519bf92477 21 #ifdef USB_ENABLED
rzrfreefr 0:16519bf92477 22 printf("usb:\n");
rzrfreefr 0:16519bf92477 23 USBKeyboard usb; ///< https://os.mbed.com/docs/mbed-os/v6.2/apis/usbkeyboard.html
rzrfreefr 0:16519bf92477 24 #endif
rzrfreefr 0:16519bf92477 25
rzrfreefr 0:16519bf92477 26 #ifdef NET_ENABLED
rzrfreefr 0:16519bf92477 27 EthernetInterface eth; ///< https://os.mbed.com/docs/mbed-os/v6.2/apis/ethernet.html
rzrfreefr 0:16519bf92477 28 eth.set_dhcp(true);
rzrfreefr 0:16519bf92477 29 eth.connect();
rzrfreefr 0:16519bf92477 30 #endif
rzrfreefr 0:16519bf92477 31
rzrfreefr 0:16519bf92477 32 DigitalOut led(LED1);
rzrfreefr 0:16519bf92477 33
rzrfreefr 0:16519bf92477 34 int16_t rmX, rmY, rmZ;
rzrfreefr 0:16519bf92477 35 acc.enable();
rzrfreefr 0:16519bf92477 36 printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
rzrfreefr 0:16519bf92477 37 while (true) {
rzrfreefr 0:16519bf92477 38 acc.getAxis(acc_data);
rzrfreefr 0:16519bf92477 39 printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z);
rzrfreefr 0:16519bf92477 40 printf("%s\n", __FILE__);
rzrfreefr 0:16519bf92477 41 led = !led;
rzrfreefr 0:16519bf92477 42 #ifdef NET_ENABLED
rzrfreefr 0:16519bf92477 43 printf("\nClient IP Address is %s\n", eth.get_mac_address());
rzrfreefr 0:16519bf92477 44 SocketAddress a;
rzrfreefr 0:16519bf92477 45 eth.get_ip_address(&a);
rzrfreefr 0:16519bf92477 46 printf("IP address: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
rzrfreefr 0:16519bf92477 47 #endif
rzrfreefr 0:16519bf92477 48 #ifdef USB_ENABLED
rzrfreefr 0:16519bf92477 49 usb.connect();
rzrfreefr 0:16519bf92477 50 usb.printf("# \n");
rzrfreefr 0:16519bf92477 51 #endif
rzrfreefr 0:16519bf92477 52 ThisThread::sleep_for(1000.f);
rzrfreefr 0:16519bf92477 53 }
rzrfreefr 0:16519bf92477 54 }