new five.Board(/* {port: "COM6"} */).on("ready", function() { // Using the piezo as a vibration sensor var sensor = new five.Sensor({ pin: "A0", freq: 25, threshold: 1 }); sensor.on("change", function () { console.log(this.value); }); // Using the piezo as a buzzer // var piezo = new five.Piezo(11); // // piezo.play({ // song: [ // ["C5", 1/4], // [null, 5/4], // ["G4", 1/4], // [null, 5/4], // ["E4", 1/4], // [null, 5/4], // ["A4", 1/4], // [null, 1/4], // ["B4", 1/4], // [null, 3/4], // ["A#4", 1/4], // [null, 1/4], // ["A4", 1/4], // [null, 3/4], // ["G4", 1/4], // [null, 1/4], // ["E5", 1/4], // [null, 3/4], // ["G5", 1/4], // [null, 1/4], // ["A5", 1/4], // [null, 3/4], // ["F5", 1/4], // [null, 1/4], // ["G5", 1/4], // [null, 3/4], // ["E5", 1/4], // [null, 3/4], // ["C5", 1/4], // [null, 1/4], // ["D5", 1/4], // [null, 1/4], // ["B4", 1/4], // [null, 3/4] // ], // tempo: 200 // }); });
board.on("ready", function() { // Create a new `sensor` hardware instance. sensor1 = new five.Sensor({ pin: "A0", freq: 300 }); sensor2 = new five.Sensor({ pin: "A1", freq: 300 }); //scale sensor A0 between 1-2 sensor1.scale([0, 1000]).on("data", function() { if(this.value < 1){ console.log('A0 Inactive'); } else{ console.log('A0 ' + this.value, this.raw); }; }); //scale sensor A1 between 1-2 sensor2.scale([0, 1000]).on("data", function() { if(this.value < 1){ console.log('A1 Inactive'); } else{ console.log('A1 ' + this.value, this.raw); }; }); });
board.on('ready', function() { photoresistor = new five.Sensor({ pin: "A0", freq: 250 }); photoresistor2 = new five.Sensor({ pin: "A1", freq: 250 }); io.on('connection', function (socket) { console.log('sockets on connection'); photoresistor.on('data', function(){ var data = this.value; socket.emit('photoData', data); }); photoresistor2.on('data', function(){ var data = this.value; socket.emit('photoData2', data); }); }); });
board.on("ready", function() { var leds = [ new five.Led({pin:7}), new five.Led({pin:8}), new five.Led({pin:9}), new five.Led({pin:10}), new five.Led({pin:11}), new five.Led({pin:12}) ]; var sensor = new five.Sensor({ pin: "A5", freq: 250 }); board.repl.inject({ sensor: sensor }); sensor.on("read", function(err, value) { var level = this.normalized * 7 / 255 - 1; console.log( value, this.normalized, level ); for (var i=0; i <= 5; i++) { if (level > i) { leds[i].on(); } else { leds[i].off(); } } }); });
board.on("ready", function() { console.log("Board connected..."); // Create a new `photoresistor` hardware instance. photoresistor = new five.Sensor({ pin: 'A0', // Analog pin 0 freq: 1000 // Collect data once per second }); // Inject the `sensor` hardware into the Repl instance's context; // Allows direct command line access board.repl.inject({ pot: photoresistor }); // Define the callback function for the photoresistor reading // The freq value used when the photoresistor was defined // determines how often this is invoked, thus controlling // the frequency of Nitrogen messages. photoresistor.on('data', function() { // Capture the ambient light level from the photoresistor var lightLevel = this.value; // Create a Nitrogen message var message = new nitrogen.Message({ type: '_lightLevel', body: { ambientLight: lightLevel } }); // Log the light level value for debugging session.log.info('Sending ambientLight: ' + lightLevel); // Send the message message.send(session); }); });
board.on("ready", function() { // Create an Led on pin 13 and strobe it on/off // Optionally set the speed; defaults to 100ms (new five.Led(13)).strobe(); // Create a new `potentiometer` hardware instance. potentiometer = new five.Sensor({ pin: "A0", freq: 200 }); // Inject the `sensor` hardware into // the Repl instance's context; // allows direct command line access board.repl.inject({ pot: potentiometer }); // "read" get the current reading from the potentiometer potentiometer.on("read", function( err, value ) { console.log( value, this.normalized ); }); });
plotly.plot(init_data,layout,function (err, res) { if (err) console.log(err); console.log(res); var stream = plotly.stream(token, function (err, res) { if (err) console.log(err); console.log(res); }); sensorLuz.scale([0, 100]).on("data", function() { var data = { x : Date(), y : this.value }; stream.write(JSON.stringify(data)+'\n'); }); sensorLuz.scale([ 0, 100 ]).on("data", function() { data = { x : getDateString(), y : 0, marker : { size : this.value } }; // write the data to the plotly stream stream.write(JSON.stringify(data)+'\n'); }); });
five.Board().on("ready", function() { var sensor = new five.Sensor("A0"); var ledVerde = new five.Led(3); var ledVermelho = new five.Led(5); sensor.on("data", function() { var temp = (this.value * 0.2027) - 82; temps.push(temp); console.log(temp + "°C"); var agora = new Date(); var minutos = getMinutesBetweenDates(lastPost, agora); console.log("@@@ MINUTOS: " + minutos); if (minutos >= 1) { console.log("*** Enviando mensagem ***"); sendMsg(); lastPost = agora; } if(temp <= tempLimite) { ledVermelho.off(); ledVerde.on(); } else { console.log("*** Temp > limite ***"); ledVermelho.on(); ledVerde.off(); } }); });
board.on("ready", function() { var sensor = new five.Sensor({ pin: "A1", freq:250, threshold: 1 }); var mic = new five.Sensor({ pin: "A0", freq:100 // threshold: 50 }); mic.within([300, 1500], function(){ console.log(this.value); console.log("sound worked"); io.emit('news'); }) // light.on("change", function() { // console.log("Ambient Light Level: ", this.level); // io.emit('news'); // }); });
board.on("ready", function() { // Plug the Rotary Angle sensor module // into the Grove Shield's A0 jack var rotary = new five.Sensor("A0"); // Plug the LCD module into any of the // Grove Shield's I2C jacks. var lcd = new five.LCD({ controller: "JHD1313M1" }); // PePo - add REPL this.repl.inject({ l : lcd }); // Set scaling of the Rotary angle // sensor's output to 0-255 (8-bit) // range. Set the LCD's background // color to a RGB value between // Red and Violet based on the // value of the rotary sensor. rotary.scale(0, 255).on("change", function() { var r = linear(0xFF, 0x4B, this.value, 0xFF); var g = linear(0x00, 0x00, this.value, 0xFF); var b = linear(0x00, 0x82, this.value, 0xFF); lcd.bgColor(r, g, b); }); });
board.on("ready", function() { var photoresistor = new five.Sensor("A0"); photoresistor.on("change", function() { console.log(this.value); }); });
board.on("ready", function() { // Create a new `photoresistor` hardware instance. photoresistor = new five.Sensor({ pin: "A2", freq: 250 }); led = new five.Led(13); // "read" get the current reading from the photoresistor photoresistor.on("read", function( err, value ) { if (value > 50) { led.on(); } else { led.off(); } console.log( value, this.normalized ); }); // Inject the `sensor` hardware into the Repl instance's context; // allows direct command line access board.repl.inject({ pot: photoresistor }); });
board.on("ready", function() { var sensor = new five.Sensor("A0"); // initialize LEDs using a for loop for (var i = 0; i < ledPins.length; i++){ var myLed = new five.Led(ledPins[i]); leds.push(myLed); } leds[0].on(); board.repl.inject({sensor: sensor}); sensor.on("data", function() { // TMP36 var celsius = ((this.value * 0.004882814) - 0.5) * 100; var fahrenheit = celsius * (9 / 5) + 32; console.log(celsius + "°C", fahrenheit + "°F"); var base = 60; var max = 95; var height = fahrenheit - base; if(height < 0) height = 0; var lights = (height * ledPins.length) / (max - base); console.log('lights ' + lights); for(var i=0;i<lights;i++){ leds[i].on(); } }); });
board.on("ready", function() { var virtual = new five.Board.Virtual( new five.Expander("PCF8591") ); var a = new five.Sensor({ // PCF8591 module YL-40 // A0:LDR(Light Dependent Resistor) // A1:NC // A2 Thermistor // A3:Potentiometer pin:"A0", board:virtual, freq: 10000 }); // PubNub初期化 var pubnub = require("pubnub")({ ssl : true, publish_key : publishKey, subscribe_key : subscribeKey }); a.on("data", function() { console.log(this.value) // パブリッシュ(送信)するデータを変数dataに格納 var data = {eon:{'brightness' : this.value}}; // データのパブリッシュ(送信) pubnub.publish({ channel : channel, message : data, callback : function(message) { console.log(message); } }); }); });
board.on("ready", function() { var button = new five.Button(12); var potentiometer = new five.Sensor({ pin: "A2", freq: 250 }); board.repl.inject({ button: button, pot: potentiometer }); button.on("down", function() { board.emit('create'); }); button.on("up", function() { board.emit('stop'); }); potentiometer.on("read", function( err, value ) { if(potValue != Math.floor(this.normalized )){ potValue = Math.floor(this.normalized); board.emit('gravityChange',{grav: potValue}); } }); });
board.on("ready", function() { var led = new five.Led(13).strobe(2000); // https://github.com/rwaldron/johnny-five/wiki/Sensor var photoSensor = new five.Sensor("A0"); // use default options var options = { pin: "A0" , freq: 1000 , threshold: 1 }; photoSensor = new five.Sensor(options); /* photoSensor.on("change", function(){ console.log("Change in light detected, new value is " + this.value + "."); }); */ photoSensor.on("data", function(){ var measurement = new Object(); measurement.value = this.value; //console.log("Current value of the light sensor is " + measurement.value + "."); var post_options = new Object(); post_options.url = 'http://iotbe-njugbe.herokuapp.com/sensor/0/measurement'; post_options.json = measurement; request.post(post_options , function(error, response, body){ if(error && response.statusCode != 200){ console.log(body); } } ); }); });
board.on("ready", function() { var sensor = new five.Sensor({ pin: "A0", freq: 1000 }); sensor.scale([0, 10]).on("data", function() { reading = this.value.toFixed(2); // message = { "Magnitude" : reading }; console.log(reading); pubnub.publish({ channel : 'pubnub-eon-iot', message : { columns:[ ['data', reading] ] } }); }); });
board.on("ready", function() { // Create a new `photoresistor` hardware instance. photoresistor = new five.Sensor({ pin: "A0", freq: 17 }); opacitySensor = new five.Sensor({ pin: "A2", freq: 17 }); // Inject the `sensor` hardware into // the Repl instance's context; // allows direct command line access board.repl.inject({ pot: photoresistor }); board.repl.inject({ pot: opacitySensor }); // "data" get the current reading from the photoresistor photoresistor.on("data", function() { console.log('A', this.value); if(socket) socket.emit("angle", this.value); }); opacitySensor.on("data", function() { console.log('o', this.value); if(socket) socket.emit("opacity", this.value); }); });
board.on("ready", function() { console.log('ready') var sensor = new five.Sensor("A0"); var touches = []; var average; sensor.scale([0, 100]).on("data", function() { touches.push(this.value * 10); }); setInterval(function() { var sum = 0; for (i = 0; i < touches.length; i++) { sum += touches[i]; } average = sum / touches.length; console.log(average) if (average > 2.1) { console.log('touch') isTouch = true; } else { console.log('no touch') isTouch = false; } touches = []; }, 100); io.sockets.on('connection', function(socket) { setInterval(function() { socket.emit('touch', isTouch); }, 100); }); });
board.on("ready", function() { var position; var getPosition = function(){ var relValue = Math.floor((dial.value/1024)*positions.length); return positions[relValue]; }; lcd.bgColor(5,10,10); var dial = new five.Sensor("A0"); dial.on("data", function() { var oldPos = position; position = getPosition(); lcd.cursor(1,0).print(position+" "); }); var button = new five.Button(4); button.on('press',function(){ setSunPosition(position); }); var times = getTimes(); var now = new Date(); var lastEvent = times.filter(function(t){ return t.time<now; }).slice(-1)[0]; var now = new Date(); lastEvent.time = new Date(new Date(now).setSeconds(now.getSeconds()+1)); scheduleEvent(lastEvent); });
var connect_the_dots=function() { console.log("Device Ready to connect its dots"); var lght = 0; var temp = 25; var light = new five.Sensor({ pin: "A2" }); light.on("change", function() { console.log("light: %d", this.value); lght = this.value; }); var temperature = new five.Temperature({ controller: "GROVE", pin: "A0" }); temperature.on("change", function() { console.log("celsius: %d", this.celsius); console.log("fahrenheit: %d", this.fahrenheit); console.log("kelvin: %d", this.kelvin); temp = this.celsius; }); // send data to Azure every 500 milliseconds setInterval(function(){ connectthedots.send_message("Light", "L", lght); connectthedots.send_message("Temp", "C", temp); }, 500); };
plotly.plot(data,layout,function (err, res) { if (err) console.log(err); console.log(res); //once it's initialized, create a plotly stream //to pipe your data! var airquality_stream = plotly.stream('25tm9197rz', function (err, res) { if (err) console.log(err); console.log(res); }); var gassensor_stream = plotly.stream('unbi52ww8a', function (err, res) { if (err) console.log(err); console.log(res); }); // this gets called every time photoresistor returns its value airquality_sensor.on("data", function() { data = { x : getDateString(), y : this.value }; // write the data to the plotly stream airquality_stream.write(JSON.stringify(data)+'\n'); }); gas_sensor.on("data", function() { data = { x : getDateString(), y : this.value }; //console.log(this.value); // write the data to the plotly stream gassensor_stream.write(JSON.stringify(data)+'\n'); }); });
arduino.on("ready", function() { var moisture = new five.Sensor("A0"); moisture.scale(0,100); var lampe = new five.Pin(7); lampe.low(); clientTwitter.stream('statuses/filter', {track: '@simplonnatacha'}, function(stream) { stream.on('data', function(tweet) { console.log(tweet.text); var motifWesh = new RegExp("wesh"); if(motifWesh.test(tweet.text)){ // Retweet clientTwitter.post('statuses/update', {status: "Je suis Natacha, mon taux d'humidité est de " + moisture.value}, function(error, tweet, response){ if(error) throw error; console.log(tweet); // Tweet body. }); } var motifArrosage = new RegExp("arrosage"); if(motifArrosage.test(tweet.text)){ // Arrosage lampe.high(); } var motifEteindre = new RegExp("éteindre"); if (motifEteindre.test(tweet.text)) { // Eteindre lampe.low(); } }); }); });
board.on("ready", function() { var slider = new five.Sensor({ pin: "I0", freq: 250 }); var joystick = new five.Joystick({ pins: ["I1","I2"], freq: 250 }); board.repl.inject({ joystick: joystick }); // 0 to 4 metres var range = [0,4]; slider.scale(range).on("change", function(err) { theDrone.setAltitude(this.scaled); }); joystick.on("axismove", function(err,timestamp) { }); });
board.on("ready", function() { // Create a new `sensor` hardware instance. sensor = new five.Sensor({ pin: "A0", freq: 250 }); board.repl.inject({ sensor: sensor }); var barra = "◼"; sensor.scale([0,100]).on("data", function() { // console.log(this.value, this.raw); barra = "◼"; for(i=0;i<=this.value;i++) barra = barra + "◼"; console.log(barra); }); // "change" // Aliases: "bend", "force", "slide", "touch" });
function sensor_creator (name, options, inputEvent, callback) { var sensor = new five.Sensor(options); sensor.on(inputEvent, function(){ callback(this.value, name) }); }
board.on('ready', () => { const photoResistor = new five.Sensor('A3'); photoResistor .on('change', function () { const currentVal = Math.round(this.value); console.log(currentVal); }); });
function boardIsReady() { /* jshint validthis: true */ var a, d; a = new five.Sensor(aCfg); d = new five.Sensor(dCfg); a.on('data', dataCallback); d.on('data', dataCallback); }
board.on('ready', function () { var servo = new five.Servo(9); var sensor = new five.Sensor("A2"); sensor.scale(0, 180).on("change", function() { // this.value will reflect a scaling from 0-1023 to 0-180 servo.to(this.value); }); });
board.on('ready', function () { sensor = new five.Sensor("A0"); sensor.on('data', function () { console.log(this.value); }); });