test-powermate.js 560 B

12345678910111213141516171819202122232425
  1. var PowerMate = require('./powermate');
  2. var powerMate;
  3. for (var i = 0; i < PowerMate.deviceCount(); i++) {
  4. console.log('opening powermate', i);
  5. powerMate = new PowerMate.PowerMate(i);
  6. powerMate.on('buttonDown', function () {
  7. console.log('button down');
  8. this.position = 0;
  9. });
  10. powerMate.on('buttonUp', function () {
  11. console.log('button up');
  12. });
  13. powerMate.on('turn', function (delta, position) {
  14. console.log('delta', delta, 'position', position);
  15. this.setLed(position % 256);
  16. });
  17. }