Upgrade to Pro — share decks privately, control downloads, hide ads and more …

社会の窓締め忘れ通知バックルを作った話epsode2

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Yoshiaki110 Yoshiaki110
April 23, 2018
1.1k

 社会の窓締め忘れ通知バックルを作った話epsode2

Avatar for Yoshiaki110

Yoshiaki110

April 23, 2018
Tweet

Transcript

  1. 「遠隔お酌」ご存知ですか センサー付きの徳利を傾けると 離れた場所にあるお酌装置がお酒を注ぐ • 実家のお父さん、お母さんと • 田舎のおじいちゃんと • 単身赴任の旦那さんと •

    海外留学の友達と 離れていても いっしょに飲んでいる気分♪ ♪ ネットのつながりを 心のつながりに 「遠隔お酌」でググってね 懇親会でデモします
  2. 状態 LED ビーコン信号 電源投入時 ゆっくり点滅 ー 磁石が近くにある (チャックが閉まっている) 消灯 ー

    磁石が近くにない∴チャックが開いている (磁石が離れてから、10秒間) 早く点滅 ー 磁石が近くにない∴チャックが開いている (磁石が離れてから、10秒以上経過) 点灯 発信
  3. #include <nRF5x_BLE_API.h> #include "setting.h" BLEDevice ble; uint8_t sid[] = {0x6F,

    0xFE}; uint8_t sdata[] = {0x6F, 0xFE, 0x02, 0x01, 0xDE, 0xAD, 0xBE, 0xEF, 0x7F, 0x00}; uint8_t hwid[] = HWID; int cnt = 0; void advertising() { ble.init(); ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS , sid, sizeof(sid)); ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA , sdata, sizeof(sdata)); ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(160); // 100ms; in multiples of 0.625ms ble.setAdvertisingTimeout(5); // 単位は秒 ble.startAdvertising(); ble.waitForEvent(); ble.stopAdvertising(); ble.shutdown(); delay(150); } void setup() { Serial.begin(9600); NRF_POWER->DCDCEN = 0x00000001; pinMode(LED, OUTPUT); pinMode(D2, INPUT_PULLUP); memcpy(&sdata[3], hwid, 5); for (int i = 0; i < 10; i++) { // 10秒間ウエイト digitalWrite(LED, HIGH); // LED ON delay(500); digitalWrite(LED, LOW); // LED OFF delay(500); } }
  4. oid loop() { int data = digitalRead(D2); if (data) {

    if (++cnt & 0x1) { digitalWrite(LED, HIGH); } else { digitalWrite(LED, LOW); } if (cnt > 30 ) { // 3秒間 digitalWrite(LED, HIGH); advertising(); // チャックが開いている時だけ通信 } } else { cnt = 0; digitalWrite(LED, LOW); } Serial.println(data, HEX); delay(100); }