Skip to content

Instantly share code, notes, and snippets.

@dudleyjosh
Last active February 12, 2019 22:54
Show Gist options
  • Save dudleyjosh/70e506ab05849791a46d99d97657d845 to your computer and use it in GitHub Desktop.
Save dudleyjosh/70e506ab05849791a46d99d97657d845 to your computer and use it in GitHub Desktop.
// I used "Generic Board + WiFi" for my Blynk Project Device Settings
// I added one button setup as a switch mapped to V1 (Blynk Virtual Pin 1) that outputs 0 or 1 to toggle one of the on board LEDs
// I added another button setup as a push button mapped to V0 (Blynk Virtual Pin 0) that outputs 0 or 1 to toggle a Tessel relay
// I had to use --full option when loading the code on the T2 for the blynk-library to run properly
// Example Code Running on Tessel 2
var tessel = require('tessel');
var RelayLib = require('relay-mono');
var relay = RelayLib.use(tessel.port['B']);
var BlynkLib = require('blynk-library');
var blynk = new BlynkLib.Blynk('YOUR_BLYNK_PROJECT_AUTH_TOKEN_HERE'); // use the auth token generated for your project in the Blynk app
var v0 = new blynk.VirtualPin(0); // setup a button in the Blynk app mapped to Virtual Pin 0
var v1 = new blynk.VirtualPin(1); // setup a button in the Blynk app mapped to Virtual Pin 1
v0.on('write', function(val) {
console.log(`v0: ${val}`);
if ( val == 1 ) {
relay.turnOn(1, function(err) {
console.log('Relay [1] is closed...');
});
}
else {
relay.turnOff(1, function(err) {
console.log('Relay [1] is open...')
});
}
});
v1.on('write', function(val) {
console.log(`v1: ${val}`);
if ( val == 1 ) {
tessel.led[3].on();
console.log('LED [3] is on...');
}
else {
tessel.led[3].off();
console.log('LED [3] is off...');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment