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.
Dependencies: ADXL345_I2C MMA8652FC Sht31 TinyGPS mbed Chainable_RGB_LED
Fork of ina-hack-test by
Diff: main.cpp
- Revision:
- 1:195da8230785
- Parent:
- 0:97a57be77fbb
- Child:
- 3:1df2b5938eb7
diff -r 97a57be77fbb -r 195da8230785 main.cpp
--- a/main.cpp Sat Jun 24 03:45:00 2017 +0000
+++ b/main.cpp Sat Jun 24 23:42:01 2017 +0000
@@ -2,25 +2,121 @@
#include "TinyGPS.h"
#include "Eeabp1.h"
+//#define TEST_ANALOG
+#define TEST_TEMP_HUMID
+#define TEST_ACC
+
+#if defined(TEST_DIGITAL_IN_INTTERUPT)
+Eeabp1 *gp;
+bool led_on = true;
+
+void flip() {
+ if (led_on)
+ gp->setLedState(LED_OFF);
+ else
+ gp->setLedState(LED_ON);
+ led_on = !led_on;
+}
+#endif /* defined(TEST_DIGITAL_IN_INTTERUPT) */
+
int main(void)
{
Eeabp1 board;
int ret = 0;
- board.setLedState(LED_BLINK_FAST);
+#if defined(TEST_DIGITAL_IN_INTTERUPT)
+ gp = &board;
+ led_on = true;
+#endif /* defined(TEST_DIGITAL_IN_INTTERUPT) */
+
+ board.setLedState(LED_ON);
board.debug("Hello ina-hack!\r\n");
board.setGrovePower(true);
+#if defined(TEST_DIGITAL_OUT) || defined(TEST_DIGITAL_IN) || defined(TEST_DIGITAL_IN_INTTERUPT)
+ board.setGrovePortType(GROVE_CH1, GROVE_DIO);
+ board.setGrovePortType(GROVE_CH2, GROVE_DIO);
+#endif
+#if defined(TEST_DIGITAL_OUT)
+ board.setGroveDioDirection(GROVE_CH1, GROVE_DIO_OUT);
+ board.setGroveDioDirection(GROVE_CH2, GROVE_DIO_OUT);
+#endif /* defined(TEST_DIGITAL_OUT) */
+#if defined(TEST_DIGITAL_IN)
+ board.setGroveDioDirection(GROVE_CH1, GROVE_DIO_IN);
+ board.setGroveDioDirection(GROVE_CH2, GROVE_DIO_IN);
+#endif /* defined(TEST_DIGITAL_IN) */
+#if defined(TEST_DIGITAL_IN_INTTERUPT)
+ board.setGroveDioDirection(GROVE_CH1, GROVE_DIO_IN, flip);
+ board.setGroveDioDirection(GROVE_CH2, GROVE_DIO_IN, flip);
+#endif /* defined(TEST_DIGITAL_IN_INTTERUPT) */
+#if defined(TEST_ANALOG)
+ board.setGrovePortType(GROVE_CH1, GROVE_ANALOG);
+ board.setGrovePortType(GROVE_CH2, GROVE_ANALOG);
+#endif /* defined(TEST_ANALOG) */
+
+#if defined(TEST_LORA)
ret = board.setLoRaPower(true);
if (ret != 0) {
-// board.setLedState(LED_OFF);
board.debug("error %d\r\n", ret);
}
+#endif /* defined(TEST_LORA) */
+#if defined(TEST_TEMP_HUMID)
+ ret = board.enableTempHumidSensor();
+ if (ret != 0)
+ board.debug("error %d\r\n", ret);
+#endif /* TEST_TEMP_HUMID */
+#if defined(TEST_ACC)
+ ret = board.enableAccelerometer();
+ if (ret != 0)
+ board.debug("error %d\r\n", ret);
+#endif /* defined(TEST_ACC) */
+#if defined(TEST_LORA)
int i = 0;
+#endif /* defined(TEST_LORA) */
+#if defined(TEST_DIGITAL_OUT)
+ bool on = true;
+#endif /* defined(TEST_DIGITAL_OUT) */
do {
- wait(10);
+ wait(2);
board.loop();
+#if defined(TEST_DIGITAL_OUT)
+ if (on) {
+ board.setGroveDio(GROVE_CH1, GROVE_DIO_HIGH);
+ board.setGroveDio(GROVE_CH2, GROVE_DIO_LOW);
+ } else {
+ board.setGroveDio(GROVE_CH1, GROVE_DIO_LOW);
+ board.setGroveDio(GROVE_CH2, GROVE_DIO_HIGH);
+ }
+ on = !on;
+#endif /* defined(TEST_DIGITAL_OUT) */
+#if defined(TEST_DIGITAL_IN)
+ board.debug("------------\r\n");
+ board.debug("P1 S1: %d\r\n", board.getGroveDio(GROVE_CH1, GROVE_SIG1));
+ board.debug("P1 S2: %d\r\n", board.getGroveDio(GROVE_CH1, GROVE_SIG2));
+ board.debug("P2 S1: %d\r\n", board.getGroveDio(GROVE_CH2, GROVE_SIG1));
+ board.debug("P2 S2: %d\r\n", board.getGroveDio(GROVE_CH2, GROVE_SIG2));
+#endif /* defined(TEST_DIGITAL_IN) */
+#if defined(TEST_ANALOG)
+ board.debug("------------\r\n");
+ board.debug("P1 S1: %2.2f\r\n", board.getGroveAnalog(GROVE_CH1, GROVE_SIG1));
+ board.debug("P1 S2: %2.2f\r\n", board.getGroveAnalog(GROVE_CH1, GROVE_SIG2));
+ board.debug("P2 S1: %2.2f\r\n", board.getGroveAnalog(GROVE_CH2, GROVE_SIG1));
+ board.debug("P2 S2: %2.2f\r\n", board.getGroveAnalog(GROVE_CH2, GROVE_SIG2));
+#endif /* defined(TEST_ANALOG) */
+#if defined(TEST_TEMP_HUMID)
+ board.debug("------------\r\n");
+ board.debug("Temp: %2.2f, Humid: %2.2f\r\n", board.getTemp(), board.getHumid());
+#endif /* defined(TEST_ANALOG) */
+#if defined(TEST_ACC)
+ int x, y, z;
+ board.getAcc(&x, &y, &z);
+ board.debug("------------\r\n");
+ board.debug("X: %d, Y: %d, Z: %d\r\n", x, y, z);
+#endif /* defined(TEST_ACC) */
+
+#if defined(TEST_LORA)
board.sendLoRaString("hello %d", i++);
+#endif /* defined(TEST_LORA) */
} while(true);
}
\ No newline at end of file
