Last active
May 5, 2018 14:49
-
-
Save hrsano645/419b172cbe280eeeb9847b40c8b82414 to your computer and use it in GitHub Desktop.
iot_ofuro_sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BLYNK_USE_DIRECT_CONNECT | |
#define BLYNK_PRINT Serial | |
#include <BlynkSimpleSerialBLE.h> | |
#include <Adafruit_BLE.h> | |
#include <Adafruit_BluefruitLE_SPI.h> | |
#include <SPI.h> | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
// DS18B20温度センサーの設定 | |
#define ONE_WIRE_BUS 6 // データ(黄)で使用するポート番号 | |
#define SENSER_BIT 9 // 精度の設定bit | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensors(&oneWire); | |
// フロートスイッチの設定 | |
int b_pin = 5; // デジタルデータ出力用ピン番号 | |
int state = 0; // ピンより取得したデータ格納用 | |
// You should get Auth Token in the Blynk App. | |
// Go to the Project Settings (nut icon). | |
char auth[] = "MYAUTHTOKEN"; | |
// Using Timer | |
BlynkTimer timer; // Create a Timer object called "timer"! | |
// SHARED SPI SETTINGS (see adafruit webpages for details) | |
#define BLUEFRUIT_SPI_CS 8 | |
#define BLUEFRUIT_SPI_IRQ 7 | |
#define BLUEFRUIT_SPI_RST 4 // Optional but recommended, set to -1 if unused | |
#define BLUEFRUIT_VERBOSE_MODE true | |
// Create ble instance, see pinouts above | |
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST); | |
void setup() { | |
Serial.begin(9600); | |
pinMode(b_pin, INPUT); // ボタンスイッチ用に入力に設定 | |
pinMode(13, OUTPUT); | |
sensors.setResolution(SENSER_BIT); | |
ble.begin(BLUEFRUIT_VERBOSE_MODE); | |
ble.factoryReset(); // Optional | |
ble.setMode(BLUEFRUIT_MODE_DATA); | |
Blynk.begin(auth, ble); | |
timer.setInterval(1000L, sendUptime); // Here you set interval (1sec) and which function to call | |
} | |
void sendUptime() | |
{ | |
// This function sends Arduino up time every 1 second to Virtual Pin (V5) | |
// In the app, Widget's reading frequency should be set to PUSH | |
// You can send anything with any interval using this construction | |
// Don't send more that 10 values per second | |
sensors.requestTemperatures(); // 温度取得要求 | |
Serial.println(sensors.getTempCByIndex(0)); //温度の取得&シリアル送信 | |
Blynk.virtualWrite(V1, sensors.getTempCByIndex(0)); | |
// フロートスイッチ用の検知用 | |
state = digitalRead(b_pin); // ピンよりデータ取得 | |
Serial.print("switch:"); | |
// フロートスイッチの状態をblinkさせる, モニタにも状況を出力 | |
if (state == 1) { | |
Serial.println("on"); // シリアルモニタに出力 | |
digitalWrite(13, HIGH); // turn the LED off by making the voltage LOW | |
Blynk.virtualWrite(V2, 255); | |
} else { | |
Serial.println("off"); // シリアルモニタに出力 | |
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW | |
Blynk.virtualWrite(V2, 0); | |
} | |
//Blynk.virtualWrite(V5, millis() / 1000); | |
} | |
void loop() | |
{ | |
Blynk.run(); // all the Blynk magic happens here | |
timer.run(); // BlynkTimer is working... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment