0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP8266 > IPアドレスを圧電ブザーで通知

Last updated at Posted at 2016-01-23
動作確認
ESP-WROOM-02
圧電ブザー LF-PB30W25C

関連 http://qiita.com/7of9/items/844bbedb2dbf20e042b9

接続

  • IO4 : 圧電ブザーの赤線
  • GND : 圧電ブザーのGND

code (v0.2)

eps8266_160123_notifyIpadr.ino
# include <ESP8266WiFi.h>
# include "wifiConfig.h"
/*
 * Define your SSID and WiFi password at [wifiConfig.h] using [TemplateWifiConfig.h]
 * 
 */

/*
 * v0.2 2016/01/23
 *   - can notify 4th IP address by sound 
 * v0.1 2016/01/23
 *   - can beep 
 */

static const int kPinSound = 4;
static IPAddress s_myIpAddress;

void sound5()
{
  digitalWrite(kPinSound, HIGH);
  delay(500);
  digitalWrite(kPinSound, LOW);
  delay(100);
}

void sound1(int maxloop)
{
  for(int loop=0; loop < maxloop; loop++) {
    digitalWrite(kPinSound, HIGH);
    delay(100);
    digitalWrite(kPinSound, LOW);
    delay(100);
  }
}

void soundLastIp(int lastIp)
{
  int workIp = lastIp;
  if (workIp >= 5) {
    sound5(); 
    workIp -= 5;
  }
  sound1(workIp);
}

void setup() {
  WiFi.begin(kWifiSsid, kWifiPass);
  while( WiFi.status() != WL_CONNECTED) {
    delay(500);  
  }
  Serial.begin(115200);
  
  pinMode(kPinSound, OUTPUT);

  s_myIpAddress = WiFi.localIP();
}

void loop() {
  soundLastIp(s_myIpAddress[3]);
  delay(5000);
}

別途必要なファイル

wifiConfig.h > WiFi接続設定を記載したファイル

参考 http://qiita.com/7of9/items/a61999a914ae02673b8d

実行

5秒おきにIPアドレスの4番目が圧電ブザーの音で通知される。

これで単体動作時にESP8266のIPが分かる (1から3番目のIPは同ネットワークに接続のPCやMacやLinuxから知ればいい)。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?