復旧方法!
node_moduleが怪しげになってうごかんくなった 以下の手順で成功
node20にして失敗しだしたのでnode18にもどして (どうやったかというと
https://nyan-kyun.verse.jp/wordpress/2024/09/25/git-sourcetree03/#google_vignetteを
参考に nvm でヴァージョン指定!)
https://qiita.com/kamiro/items/b509e30fa62279a82bbcの5の方法で復旧できた
https://qiita.com/pyon_kiti_jp/items/6a751779f4baf165896bでnvm固定!
-------------------hcsr04 他-pir ,piezo,lm35---------------
pirはあっさりうごいた...ふかぼりいずれ必要 lm35は表示がはやすぎ。。。深堀必要
piezoもあっさり動いた ただ以下のコードで最初のpiezo.playのみ実行される
あとのはreplにコピペで動いた なおプラマイがあるのがアクティブ、ないのがパッシブ
var five = require("johnny-five"), board = new five.Board(); board.on("ready", function() { // Creates a piezo object and defines the pin to be used for the signal var piezo = new five.Piezo(3); // Injects the piezo into the repl board.repl.inject({ piezo: piezo }); // Plays a song piezo.play({ // song is composed by an array of pairs of notes and beats // The first argument is the note (null means "no note") // The second argument is the length of time (beat) of the note (or non-note) song: [ ["C4", 1 / 4], ["D4", 1 / 4], ["F4", 1 / 4], ["D4", 1 / 4], ["A4", 1 / 4], [null, 1 / 4], ["A4", 1], ["G4", 1], [null, 1 / 2], ["C4", 1 / 4], ["D4", 1 / 4], ["F4", 1 / 4], ["D4", 1 / 4], ["G4", 1 / 4], [null, 1 / 4], ["G4", 1], ["F4", 1], [null, 1 / 2] ], tempo: 100 }); // Plays the same song with a string representation piezo.play({ // song is composed by a string of notes // a default beat is set, and the default octave is used // any invalid note is read as "no note" song: "C D F D A - A A A A G G G G - - C D F D G - G G G G F F F F - -", beats: 1 / 4, tempo: 100 }); });
https://denshibu.blog.fc2.com/blog-entry-114.html?sp を参考にPingFirmata.inoをunoへ
インストするのがキモ!
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Proximityオブジェクトを作成
var proximity = new five.Proximity({
controller: "HCSR04",
pin: 7,
freq: 10000
});
// データを取得して距離を表示
proximity.on("data", function() {
console.log("Proximity: ");
console.log(" cm : ", this.cm);
console.log(" in : ", this.in);
console.log("-----------------");
});
// 「change」イベント:障害物が変更されたときに発生する
proximity.on("change", function() {
console.log("The obstruction has moved.");
});
});
-----------------------------led blink------------------------------------------
https://johnny-five.io/examples/ :: miscelaneous examples
https://qiita.com/masato/items/9dad71eca295088e14e5 :: 補遺
{ "name": "johnny-five-start", "version": "0.0.1", "private": true, "dependencies": { "johnny-five": "0.8.48" }, "scripts": {"start": "node app.js"} }
上記のpackage.jsonでnpm startできた、ちなみにctl-c x 2でexitできた!
ただしapp.jsはled1.jsを参考に以下とした
const{Board,Led} = require("johnny-five");
const board = new Board();
board.on("ready", function() {
const led = new Led(12);
led.blink(1000);
});
---------led1.js-----------------------------------------
const { Board, Led } = require("johnny-five");
const board = new Board();
board.on("ready", () => {
const led = new Led(12);
led.on();
board.on("exit", () => {
led.off();
});
});
--------------servo1.js--------------------
servo :: https://dev.classmethod.jp/articles/genuino-101johnny-five-servo/
var five = require('johnny-five');
// Genuino が接続されているポート番号 ( `/dev/tty*` (Mac/Linux) or `COM*` (Windows) )
var board = new five.Board();
board.on('ready', function() {
var servo = new five.Servo({
'pin' : 10
});
this.repl.inject({
'servo' : servo
});
servo.sweep({
'range' : [45, 135],
'interval' : 10000
});
});
0 件のコメント:
コメントを投稿