Last active
October 11, 2019 22:27
-
-
Save alexglow/75fd48da5a60495b8c873908f03ea3de to your computer and use it in GitHub Desktop.
how kill everloop when kill tag ???
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const matrix = require("@matrix-io/matrix-lite"); | |
const shell = require('shelljs') | |
const nfc = require("@matrix-io/matrix-lite-nfc"); | |
var mode = 0; | |
everLoop(); | |
nfc.read.start({rate:100, info:true}, (code, tag)=>{ | |
if (code === 256){ | |
console.log("Tag Was Scanned"); | |
console.log(tag); | |
console.log(tag.info.UID); | |
if (tag.info.UID === "04EBFA8AA86480"){ | |
shell.exec('/home/pi/start_robot'); | |
mode = 1; | |
} | |
if (tag.info.UID === "0435F58AA86481"){ | |
shell.exec('~/runmyrobot/scripts/kill_command'); | |
mode = 0; | |
} | |
} | |
else if (code === 1024) | |
console.log("Nothing Was Scanned"); | |
}); | |
/* here beginneth the everloop function */ | |
function everLoop() { | |
let everloop = new Array(matrix.led.length); | |
let ledAdjust = 0.0; | |
if (everloop.length == 35) { | |
ledAdjust = 0.51; // MATRIX Creator | |
} else { | |
ledAdjust = 1.01; // MATRIX Voice | |
} | |
let frequency = 0.375; | |
let counter = 0.0; | |
let tick = everloop.length - 1; | |
setInterval(()=>{ | |
if (mode === 1){ | |
// Create rainbow | |
for(i = 0; i < everloop.length; i++) { | |
let led = {}; | |
led.r = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*240))*155+100)/10)); | |
led.g = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*120))*155+100)/10)); | |
led.b = Math.round(Math.max(0, (Math.sin(frequency*counter)*155+100)/10)); | |
counter += ledAdjust; | |
everloop[i] = led; | |
}; | |
// Slowly show rainbow | |
if (tick != 0) { | |
for (i = tick; i > 0; i--) { | |
everloop[i] = {}; | |
} | |
tick--; | |
} | |
matrix.led.set(everloop); | |
} | |
else { | |
matrix.led.set("black"); | |
} | |
},200); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const matrix = require("@matrix-io/matrix-lite"); | |
const shell = require('shelljs') | |
const nfc = require("@matrix-io/matrix-lite-nfc"); | |
var mode = 0; | |
everLoop(); | |
nfc.read.start({rate:100, info:true}, (code, tag)=>{ | |
if (code === 256){ | |
console.log("Tag Was Scanned"); | |
console.log(tag); | |
console.log(tag.info.UID); | |
if (tag.info.UID === "04EBFA8AA86480"){ | |
shell.exec('/home/pi/start_robot'); | |
mode = 1; | |
} | |
if (tag.info.UID === "0435F58AA86481"){ | |
shell.exec('~/runmyrobot/scripts/kill_command'); | |
mode = 0; | |
} | |
} | |
else if (code === 1024) | |
console.log("Nothing Was Scanned"); | |
}); | |
/* here beginneth the everloop function */ | |
function everLoop() { | |
let everloop = new Array(matrix.led.length); | |
let ledAdjust = 0.0; | |
if (everloop.length == 35) { | |
ledAdjust = 0.51; // MATRIX Creator | |
} else { | |
ledAdjust = 1.01; // MATRIX Voice | |
} | |
let frequency = 0.375; | |
let counter = 0.0; | |
let tick = everloop.length - 1; | |
setInterval(()=>{ | |
if (mode === 1){ | |
// Create rainbow | |
for(i = 0; i < everloop.length; i++) { | |
let led = {}; | |
led.r = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*240))*155+100)/10)); | |
led.g = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*120))*155+100)/10)); | |
led.b = Math.round(Math.max(0, (Math.sin(frequency*counter)*155+100)/10)); | |
counter += ledAdjust; | |
everloop[i] = led; | |
}; | |
// Slowly show rainbow | |
if (tick != 0) { | |
for (i = tick; i > 0; i--) { | |
everloop[i] = {}; | |
} | |
tick--; | |
} | |
matrix.led.set(everloop); | |
} | |
else { | |
matrix.led.set("black"); | |
} | |
},200); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const matrix = require("@matrix-io/matrix-lite"); | |
const shell = require('shelljs') | |
const nfc = require("@matrix-io/matrix-lite-nfc"); | |
nfc.read.start({rate:100, info:true}, (code, tag)=>{ | |
if (code === 256){ | |
console.log("Tag Was Scanned"); | |
console.log(tag); | |
console.log(tag.info.UID); | |
if (tag.info.UID === "04EBFA8AA86480"){ | |
shell.exec('/home/pi/start_robot'); | |
everLoop(); | |
} | |
if (tag.info.UID === "0435F58AA86481"){ | |
shell.exec('~/runmyrobot/scripts/kill_command'); | |
matrix.led.set("black"); | |
} | |
} | |
else if (code === 1024) | |
console.log("Nothing Was Scanned"); | |
}); | |
/* here beginneth the eveloop function */ | |
function everLoop() { | |
let everloop = new Array(matrix.led.length); | |
let ledAdjust = 0.0; | |
if (everloop.length == 35) { | |
ledAdjust = 0.51; // MATRIX Creator | |
} else { | |
ledAdjust = 1.01; // MATRIX Voice | |
} | |
let frequency = 0.375; | |
let counter = 0.0; | |
let tick = everloop.length - 1; | |
setInterval(()=>{ | |
// Create rainbow | |
for(i = 0; i < everloop.length; i++) { | |
let led = {}; | |
led.r = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*240))*155+100)/10)); | |
led.g = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*120))*155+100)/10)); | |
led.b = Math.round(Math.max(0, (Math.sin(frequency*counter)*155+100)/10)); | |
counter += ledAdjust; | |
everloop[i] = led; | |
}; | |
// Slowly show rainbow | |
if (tick != 0) { | |
for (i = tick; i > 0; i--) { | |
everloop[i] = {}; | |
} | |
tick--; | |
} | |
matrix.led.set(everloop); | |
},200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment