dwyl / iot-decibel-meter

A decibel meter built with an arduino
40 stars 8 forks source link

Lcd with voltage from microphone #8

Closed naazy closed 6 years ago

naazy commented 7 years ago

Displaying voltage(?) from microphone on lcd with this set up http://johnny-five.io/examples/lcd/. Next step is to look at how to convert this to decibels

var five = require("johnny-five"), board, lcd;

var analog = "A0"
var digital = "13";

board = new five.Board();
board.on("ready", function() {
  var led = new five.Led(3);
  var lcd = new five.LCD({
    // LCD pin name  RS  EN  DB4 DB5 DB6 DB7
    // Arduino pin # 7    8   9   10  11  12
    pins: [7, 8, 9, 10, 11, 12],
    backlight: 2,
    rows: 2,
    cols: 20
    // Options:
    // bitMode: 4 or 8, defaults to 4
    // lines: number of lines, defaults to 2
    // dots: matrix dimensions, defaults to "5x8"
  });

  // Tell the LCD you will use these characters:
  lcd.useChar("heart");

  lcd.cursor(1, 0);

  this.repl.inject({
    lcd: lcd
  });

  var analogSensor = new five.Sensor({pin:analog,
    freq: 1000
    });

  analogSensor.on("data", function() {
  //  lcd.print(this.value);

    if(this.value > 500){
      lcd.clear().cursor(0, 0).print(this.value + " Too loud :(");
      led.on();
    } else {
      lcd.clear().print(this.value + " :heart:");
      lcd.cursor(1, 0);
      led.off();
    }
 });

});
naazy commented 6 years ago

Closing because I have already incorporated the research into the code