Coder Social home page Coder Social logo

tessel-pulse's Introduction

tessel-pulse

Pulse your LEDs with tessel. This module works only on PWM pins

Example

var tessel = require('tessel');
var mqtt = require('mqtt');
var port = tessel.port['GPIO'];
var pulse = require('tessel-pulse');
var pin = port.pwm[0]; // G4
var stop = pulse(pin, {
  type: 'pulse', // or 'blink'
  steps: 200, // the number of increments of the intesity of the led's light
  changeFrequency: 500 // ms after the step is incremented/decremented
});
setTimeout(stop, 10000); // blink for 10s

Example with MQTT

First, install MQTT.js with:

npm install mqtt --save

Then:

var tessel = require('tessel');
var mqtt = require('mqtt');
var port = tessel.port['GPIO'];
var pulse = require('tessel-pulse');
var pin = port.pwm[0]; // G4
var stop = null;
var client = mqtt.connect('mqtt://test.mosca.io');

port.pwmFrequency(10000) // set the PWM frequncy to 10kHz

client.publish('leds/matteo/hello', 'I\'m online!')
client.subscribe('leds/matteo/+')

client.on('message', function(topic, payload) {
  var command = topic.replace('leds/matteo/', '');
  console.log(payload)

  if (!payload)
    payload = {}
  else
    try {
      payload = JSON.parse(payload)
    } catch(err) {
      console.log('wrong json', err)
    }

  if (stop) stop()

  switch(command) {
    case 'start':
      stop = pulse(pin, payload)
      console.log('pulser started');
      break;
    case 'stop':
      console.log('pulser stopped');
      stop = null
      break;
  }
})

console.log('hello from my led!')

License

ISC

tessel-pulse's People

Contributors

mcollina avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.