8
7

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.

ズンドコキヨシ with C拡張 by ESP8266 + Analog Discovery 2

Last updated at Posted at 2016-03-13

方法

  • 0-1Vの電圧をAD取込する
  • AD取込値(10bit: 1024)のLSBが0か1かで{Doko, Zun}の判別
  • Zunが4つ続いた後にDokoが来たらKIYOSHI!

道具

  • Analog Discovery 2 (以下AD2)
    • Wavegenで0-1Vのノイズ電圧を発生させる > Qiita記事
  • ESP8266 (WiFi搭載マイコン)
    • AD取込をする
    • 方法に記載の処理を行いKIYOSHI判定をする

code v0.1

esp8266_160313_zundoko.ino
// AD取り込みのためのおまじない
extern "C" {
#include "user_interface.h"
}

static const String msg[2] = {
  "Doko",
  "Zun",
};

static int s_zunCount = 0;
static bool s_stopCondition = false;
static int s_totalTime_sec = 0;

void setup() {
  Serial.begin(115200); // 結果出力用シリアルの設定
  Serial.println(""); // to separate line
}

void loop() {
  if (s_stopCondition) {
    return;
  }
  
  uint ADvalue;
  ADvalue = system_adc_read(); // 0..1024 のAD取込

  int rnd = (ADvalue % 2);
  Serial.println(msg[rnd]);

  if (rnd == 1) {
    s_zunCount++;
  } else {
    if (s_zunCount == 4) {
      Serial.println("KIYOSHI!");
      s_stopCondition = true;
      Serial.print("Total time(sec):");
      Serial.println(s_totalTime_sec);
      return;
    }
    s_zunCount = 0;
  }

  s_totalTime_sec++;
  delay(1000); // msec
}

結果

結果
(略)
Doko
Zun
Zun
Doko
Zun
Zun
Doko
Zun
Doko
Zun
Zun
Zun
Zun
Doko
KIYOSHI!
Total time(sec):46

写真

  • 黄色: AD取込の電圧
  • 黒: GND

DSC_0147.JPG

8
7
2

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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?