<commit_before>var Board = require("../lib/board.js"),
    events = require("events"),
    util = require("util"),
    Timer = require("nanotimer");

function Piezo( opts ) {

  Board.Device.call(
    this, opts = Board.Options( opts )
  );

  // Hardware instance properties
  this.board = Board.mount( opts );
  this.firmata = this.board.firmata;
  this.mode = this.firmata.MODES.OUTPUT;
  this.pin = opts.pin || 3;

  this.notes = {
    "c": 1915,
    "d": 1700,
    "e": 1519,
    "f": 1432,
    "g": 1275,
    "a": 1136,
    "b": 1014,
    "C": 956
  };

  // Set the pin to INPUT mode
  this.firmata.pinMode( this.pin, this.mode );

  // Piezo instance properties
  this.interval = null;

  this.playing = false;

  this.queue = [];
}

util.inherits( Piezo, events.EventEmitter );

Piezo.prototype.tone = function( tone, duration ) {
  var timer = new Timer();
  var value = 1;

  timer.setInterval(function () {
      value = value === 1 ? 0 : 1;
      this.firmata.digitalWrite( this.pin, value );
    }.bind(this), null, tone + 'u', function () {});

  timer.setTimeout(function () {
    timer.clearInterval();
  }.bind(this), null, duration + 'm');
};

Piezo.prototype.song = function( tune, beats ){

  var tempo = 150;
  var self = this;
  var note, duration;
  var i = 0;

  function next(){
    note = tune[i];
    duration = beats[i] * tempo;

    if (i++ === tune.length) {
      return;
    }

    if (note === " ") {
      self.noTone();
      setTimeout(next, duration);
    } else {
      var myNote = self.notes[note];
      self.tone(myNote, duration);
      setTimeout(next, duration);
    }
  }

  next();
};

Piezo.prototype.noTone = function(){
  this.firmata.digitalWrite( this.pin, 0 );
};

module.exports = Piezo;<commit_msg>Minor style fixes<commit_after>var Board = require("../lib/board.js"),
    events = require("events"),
    util = require("util"),
    Timer = require("nanotimer");

function Piezo( opts ) {

  Board.Device.call(
    this, opts = Board.Options( opts )
  );

  // Hardware instance properties
  this.board = Board.mount( opts );
  this.firmata = this.board.firmata;
  this.mode = this.firmata.MODES.OUTPUT;
  this.pin = opts.pin || 3;

  this.notes =  // Set the pin to INPUT mode
  this.firmata.pinMode( this.pin, this.mode );

  // Piezo instance properties
  this.playing = false;
}

util.inherits( Piezo, events.EventEmitter );

Piezo.Notes = {
  "c": 1915,
  "d": 1700,
  "e": 1519,
  "f": 1432,
  "g": 1275,
  "a": 1136,
  "b": 1014,
  "C": 956
};

Piezo.prototype.tone = function( tone, duration ) {
  var timer = new Timer();
  var value = 1;

  timer.setInterval(function () {
      value = value === 1 ? 0 : 1;
      this.firmata.digitalWrite( this.pin, value );
    }.bind(this), null, tone + 'u', function () {});

  timer.setTimeout(function () {
    timer.clearInterval();
  }.bind(this), null, duration + 'm');
};

Piezo.prototype.song = function( tune, beats ){
  var tempo = 150;
  var note, duration;
  var i = 0;

  function next() {
    note = tune[i];
    duration = beats[i] * tempo;

    if (i++ === tune.length) {
      this.playing = false;
      return;
    }

    if (note === " ") {
      this.noTone();
      setTimeout(next.bind(this), duration);
    } else {
      var myNote = Piezo.Notes[note];
      this.tone(myNote, duration);
      setTimeout(next.bind(this), duration);
    }
  }

  next.call(this);
};

Piezo.prototype.noTone = function(){
  this.firmata.digitalWrite( this.pin, 0 );
};

module.exports = Piezo;
{'fraction_non_alphanumeric': 0.17242363688267198, 'fraction_numerical': 0.023408506994005138, 'mean_word_length': 2.711864406779661, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1008794', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1230, 'n_words': 290}