hybridgroup / cylon

JavaScript framework for robotics, drones, and the Internet of Things (IoT)
https://cylonjs.com
Other
4.2k stars 360 forks source link

Reference: my is not defined #370

Closed Pazox closed 7 years ago

Pazox commented 7 years ago

I am trying to use Cylon.js with my arduino, and I got stuck with this problem. the code I use:

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    arduino: { adaptor: 'firmata', port: 'COM3' }
  },

  devices: {
    led: { driver: 'led', pin: 2}
  },

   work: function() {
    every((1).second(), function() {
        my.led.toggle();
    });
  }
});
Cylon.start();

the error I get:

        my.led.toggle();
        ^

ReferenceError: my is not defined

I tried to switch 'my' with 'this' and the error I get is:

        this.led.toggle();
                ^

TypeError: Cannot read property 'toggle' of undefined

Any suggestions? Thanks in advance.

vkarpuram commented 7 years ago

Modify your work function like so:

work: function(my) { every((1).second(), function() { my.led.toggle(); }); }

Pazox commented 7 years ago

That worked! Thanks.