npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ux-xu/cocorokit-plus-js-sdk

v1.3.0

Published

cocorokit+ JavaScript SDK

Downloads

26

Readme

English

cocorokit+ JavaScript SDK

ココロキット+を JavaScript と TypeScript から動かすための SDK

You can use cocorokit+ from JavaScript and TypeScript

必要要件 | Requirements

本 SDK は Web Bluetooth API を使っています。Web Bluetooth API は現在(2020-07-25)使えるブラウザが限られているため次のリンクから、ご利用の環境で利用できるかご確認ください(https://caniuse.com/#feat=web-bluetooth)。

This module uses Web BLuetooth API. The support of API is limited. Please confirm your device following the link (https://caniuse.com/#feat=web-bluetooth).

使い方 | How to use

ココロキット+に接続して LED を赤色に光らせるサンプルです。

Connect to cocorokit+ and turn Red LED on.

import CocorokitPlus from "@ux-xu/cocorokit-plus-js-sdk";

const ccrpls = CocorokitPlus.find(CocorokitPlus.defaultFilter);
ccrpls.setLED(CocorokitPlus.LED_R, 100);

関数の説明 | About funcitons

ココロキット+との通信を必要とする関数は async / await で実装しています。

cocorokit+ JS SDK uses async / await function.

サーボモータの操作 | Control servo motor (change duty)

cocoro.setPwmDuty(CocorokitPlus.PWM0, 1450); // サーボ0 の duty を 1450 usec に変更 | change servo zero's duty to 1450 usec
cocoro.setPwmDutyAll(600, 600, 600, 600); // サーボ0 から 3 の duty を同時に 600usec に変更 | change all servos's duty to 600 usec simultaneously
cocoro.setPwmDutyTime(CocorokitPlus.PWM0, 2300, 2000); // 2000 ミリ秒に duty が 2300 usec になるようにサーボ0 を動かす | change servo zero's duty 2300 usec after 2000 milli seconds.

setPwmDutyTime は duty が変化する速度をゆっくりにしたいときに利用します。

You can use setPwmDutyTime when you want to change servo duty slowly.

センサーの値の取得 | Get value of sensors

const onChanged = (data) => {
  const input3 = (data >> 3) & 0x01;
  console.log(input3); // 0 or 1
  const input4 = (data >> 4) & 0x01;
  console.log(input4); // 0 or 1
};

cocoro.startDigitalInputNotification(onChanged);

ココロキット+は、センサーの値が変化すると通知が送ります。
通知された時に動かす関数を設定するコトでセンサの値に応じた操作が可能です。

data は 8bit の Unsigned Int 型で送られてきます。
ココロキット+のセンサ 1 とセンサ 2 は、3bit 目と 4bit 目に割り当てられています。

Cocorokit+ notify when digital input value changed. Please set callback function.

Callback functions arguments (data) is 8 bit unsigned int. Sensor 1 is on 3bit and Sensor 2 is on 4bit.

LED の表示 | turn on LED

LED は PWM 制御をしているため、明るさの強さを指定します。

Cocorokit+ control LED using PWM. Please set target LED and brightness (0-100).

cocoro.setLED(CocorokitPlus.LED_R, 100); // 赤を最大強度で光らせる | bright Red LED by max power
cocoro.setLED(CocorokitPlus.LED_G, 50); // 緑を50%の強度で光らせる | bright Green LED by 50%
cocoro.setLED(CocorokitPlus.LED_R, 0); // 赤色を消す | turn Red LED off