LoginSignup
0
0

More than 1 year has passed since last update.

micro:bitでハンドスピナーの回転数を計測する

Posted at

概要

micro:bitとフォトリフレクタでハンドスピナーの回転数を計測する仕組みを作りました。

使用したもの

①micro:bit v2
②フォトリフレクタKKHMF TCRT5000

説明

黒テープを張っている個所は幅があるため、
LastStatus、ThisStatus
の二つで、

黒テープのの中:■■ 1,1 
黒テープの端: ■□ 1,0  計測開始 
それ以外:   □□ 0,0
黒テーブの左端:□■ 0,1 計測終了

上記のステータス管理をして時間を計測をしています。

コード

https://makecode.microbit.org/_F91gdfbxUUHM
MBハンドスピナーの回転数.JPG

HS.js
let V_IN = 0
basic.showIcon(IconNames.Heart)
basic.pause(1000)
basic.showIcon(IconNames.EigthNote)
let CNT = 0
let time = 0
let st_time = 0
let ed_time = 0
let this_status = 0
let last_status = 0
basic.forever(function () {
    V_IN = pins.digitalReadPin(DigitalPin.P0)
    this_status = V_IN
    serial.writeValue("IN", this_status)
    if (last_status == 1 && this_status == 0) {
        st_time = input.runningTime()
    } else if (last_status == 0 && this_status == 1) {
        ed_time = input.runningTime()
        time = ed_time - st_time
        serial.writeValue("TimeMS", time)
    } else if (last_status == 1 && this_status == 1) {
        st_time = 0
        ed_time = 0
    }
    last_status = this_status
})
0
0
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
0