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 Chainable_RGB_LED EEAB-P1 MMA8652FC Sht31 TinyGPS mbed
Fork of ina-hack-test by
Revision 7:6a352003742d, committed 2017-08-22
- Comitter:
- sonson
- Date:
- Tue Aug 22 09:32:40 2017 +0000
- Parent:
- 6:ae7b9f0a13f7
- Child:
- 8:06b52bde3c82
- Commit message:
- RGBLED???
Changed in this revision
| Chainable_RGB_LED.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Chainable_RGB_LED.lib Tue Aug 22 09:32:40 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Seeed/code/Chainable_RGB_LED/#50d0a66599e1
--- a/main.cpp Tue Aug 22 08:50:17 2017 +0000
+++ b/main.cpp Tue Aug 22 09:32:40 2017 +0000
@@ -1,8 +1,10 @@
#include "mbed.h"
#include "TinyGPS.h"
#include "Eeabp1.h"
+#include "ChainableLED.h"
-#define TEST_ANALOG // WaterSensor(ハイインピ過ぎる),SoundSensor(動くが設計に問題有),MoistureSensor,LightSensor,MotionSensor
+
+//#define TEST_ANALOG // WaterSensor(ハイインピ過ぎる),SoundSensor(動くが設計に問題有),MoistureSensor,LightSensor,MotionSensor
//#define TEST_TEMP_HUMID //SHT31
//#define TEST_ACC // ADXL345
//#define TEST_DIGITAL_IN // Button,Switch
@@ -10,6 +12,11 @@
//#define TEST_DIGITAL_IN_INTTERUPT
//
+// RGBLED Support
+//
+ChainableLED color_led(P0_13, P0_12, 1); // ChainableLED(clk, data, number_of_leds)
+
+//
// 1Wire Support
//
I2C i2c(P0_30, P0_7);
@@ -44,15 +51,11 @@
i2c.start();
i2c.write((address << 1) + 1);
- if (datacount == 1)
- {
+ if (datacount == 1) {
*data = i2c.read(false);
- }
- else
- {
+ } else {
int i = 0;
- for (i = 0; i < datacount - 1; i++)
- {
+ for (i = 0; i < datacount - 1; i++) {
*(data + i) = i2c.read(false);
}
*(data + datacount - 1) = i2c.read(true);
@@ -83,8 +86,7 @@
// LE 1-2バイト目が温度 0.0625℃精度
uint8_t l = 0;
uint8_t data[8];
- for (l = 0; l < 8; l++)
- {
+ for (l = 0; l < 8; l++) {
SendRegDataI2c(0x18, 0x96); // 1-Wire Read Byte Command(0x96)
wait_us(10000);
RecieveDataI2c(0x18, 0xE1, 0xE1, &data[l], 1); // Read from Pointer's DATA(0xE1)
@@ -157,56 +159,57 @@
static void LoopGps()
{
if(gpsPowerOn == true) {
- // データが無い時は、0xB4,0xA7を繰り返す
- // 有効なデータが来るまで、FIFOを最大1/4読む
- for(int j=0;j<512;j++){
- spiData = spi.write(0x00);
+ // データが無い時は、0xB4,0xA7を繰り返す
+ // 有効なデータが来るまで、FIFOを最大1/4読む
+ for(int j=0; j<512; j++) {
+ spiData = spi.write(0x00);
if(spiData != 0xB4 && spiData != 0xA7)break;
- }
- if(spiData == 0xB4 || spiData == 0xA7) return; // 有効なデータが無かった
- // NMEAをデコードする
- // 0xB4がSPIデータ終端 各NMEAセンテンスは0x0d,0x0Aでセパレートされている為、一度だけのリードで問題無い。
+ }
+ if(spiData == 0xB4 || spiData == 0xA7) return; // 有効なデータが無かった
+ // NMEAをデコードする
+ // 0xB4がSPIデータ終端 各NMEAセンテンスは0x0d,0x0Aでセパレートされている為、一度だけのリードで問題無い。
#ifdef GPSDEBUG
- int i=0;
- buffer[i] = spiData;
- i++;
+ int i=0;
+ buffer[i] = spiData;
+ i++;
#endif
- while(1) {
- spiData = spi.write(0x00);
- if(spiData == 0xB4) { // 終端検出
+ while(1) {
+ spiData = spi.write(0x00);
+ if(spiData == 0xB4) { // 終端検出
#ifdef GPSDEBUG
- buffer[i] = 0x00;
+ buffer[i] = 0x00;
#endif
- break;
- }
-#ifdef GPSDEBUG
- buffer[i] = spiData;
- i++;
-#endif
- gps.encode(spiData);
- }
- gps.get_position(&latitude, &longitude, &fix_age);
- altitude = gps.altitude(); // 高度取得は正しく動かない?
-/*
+ break;
+ }
#ifdef GPSDEBUG
- pc.debug("%s", buffer); // NMEAデータ表示
- pc.debug("POS:%d,%d,%d\r\n", latitude,longitude,altitude); // GPS情報表示
+ buffer[i] = spiData;
+ i++;
#endif
-*/
- // GPS状態判定の為、GPS座標を定期的にリセットする
- if(needGpsRefresh == true) {
- gps.reset_ready();
- gps.reset_pos();
- needGpsRefresh = false;
- }
+ gps.encode(spiData);
}
+ gps.get_position(&latitude, &longitude, &fix_age);
+ altitude = gps.altitude(); // 高度取得は正しく動かない?
+ /*
+ #ifdef GPSDEBUG
+ pc.debug("%s", buffer); // NMEAデータ表示
+ pc.debug("POS:%d,%d,%d\r\n", latitude,longitude,altitude); // GPS情報表示
+ #endif
+ */
+ // GPS状態判定の為、GPS座標を定期的にリセットする
+ if(needGpsRefresh == true) {
+ gps.reset_ready();
+ gps.reset_pos();
+ needGpsRefresh = false;
+ }
+ }
}
#if defined(TEST_DIGITAL_IN_INTTERUPT)
Eeabp1 *gp;
bool led_on = true;
-void flip() {
+void flip()
+{
if (led_on)
gp->setLedState(LED_OFF);
else
@@ -230,10 +233,23 @@
board.setGrovePower(true);
+
+ // RGBLEDデモ
+ // 本来はデータシート通り5Vで操作させないと色がおかしいが、
+ // 3.3Vでも動作自体は問題無い
+ uint8_t R = 50;
+ uint8_t G = 100;
+ uint8_t B = 200;
+ board.setGrovePortType(GROVE_CH1, GROVE_DIO);
+ board.setGroveDioDirection(GROVE_CH1, GROVE_DIO_OUT);
+ wait(0.1);
+ // ChainableLED.setColorRGB(index_of_led, red, green, blue)
+ color_led.setColorRGB(0, R, G, B); // increase brightness cascade down chain of LED's
+
/*
// GPSデモ
GpsPower(true); // バッテリー駆動の場合、GPS電源をこまめに切ることを推奨します
- while(true)
+ while(true)
{
LoopGps(); // バッファが溢れる迄(目安2秒)にこのループを回して下さい。
board.debug("POS:%d,%d,%d\r\n", latitude,longitude,altitude); // GPS情報表示
@@ -248,14 +264,14 @@
}
}
*/
-
-/*
- // 1Wireデモ
- while(1){
- wait(1);
- board.debug("TEMP:%f\r\n", GetTempFrom1Wire());
- }
-*/
+ /*
+ // 1Wireデモ
+ while(1)
+ {
+ wait(1);
+ board.debug("TEMP:%f\r\n", GetTempFrom1Wire());
+ }
+ */
#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);
@@ -310,8 +326,7 @@
board.setGroveDio(GROVE_CH1, GROVE_SIG2 , GROVE_DIO_LOW);
board.setGroveDio(GROVE_CH2, GROVE_SIG1 , GROVE_DIO_HIGH);
board.setGroveDio(GROVE_CH2, GROVE_SIG2 , GROVE_DIO_LOW);
- }
- else {
+ } else {
board.setGroveDio(GROVE_CH1, GROVE_SIG1 , GROVE_DIO_LOW);
board.setGroveDio(GROVE_CH1, GROVE_SIG2 , GROVE_DIO_HIGH);
board.setGroveDio(GROVE_CH2, GROVE_SIG1 , GROVE_DIO_LOW);
@@ -347,5 +362,5 @@
#if defined(TEST_LORA)
board.sendLoRaString("hello %d", i++);
#endif /* defined(TEST_LORA) */
-} while (true);
+ } while (true);
}
