Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // I used "Generic Board + WiFi" for my Blynk Project Device Settings
  2. // 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
  3. // 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
  4.  
  5. // I had to use --full option when loading the code on the T2 for the blynk-library to run properly
  6.  
  7. // Example Code Running on Tessel 2
  8. var tessel = require('tessel');
  9.  
  10. var RelayLib = require('relay-mono');
  11. var relay = RelayLib.use(tessel.port['B']);
  12.  
  13. var BlynkLib = require('blynk-library');
  14. var blynk = new BlynkLib.Blynk('YOUR_BLYNK_PROJECT_AUTH_TOKEN_HERE'); // use the auth token generated for your project in the Blynk app
  15.  
  16. var v0 = new blynk.VirtualPin(0); // setup a button in the Blynk app mapped to Virtual Pin 0
  17. var v1 = new blynk.VirtualPin(1); // setup a button in the Blynk app mapped to Virtual Pin 1
  18.  
  19. v0.on('write', function(val) {
  20.  
  21. console.log(`v0: ${val}`);
  22.  
  23. if ( val == 1 ) {
  24. relay.turnOn(1, function(err) {
  25. console.log('Relay [1] is closed...');
  26. });
  27. }
  28. else {
  29. relay.turnOff(1, function(err) {
  30. console.log('Relay [1] is open...')
  31. });
  32. }
  33.  
  34. });
  35.  
  36. v1.on('write', function(val) {
  37.  
  38. console.log(`v1: ${val}`);
  39.  
  40. if ( val == 1 ) {
  41. tessel.led[3].on();
  42. console.log('LED [3] is on...');
  43. }
  44. else {
  45. tessel.led[3].off();
  46. console.log('LED [3] is off...');
  47. }
  48.  
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement