Mirror ball with Clapping

このエントリーをはてなブックマークに追加

This mirror ball rotate when someone clap.
I created with obniz in 1 hour.

Program

<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@2.0.2/obniz.js" crossorigin="anonymous"></script>
</head>
<body>

<div id="obniz-debug"></div>
<h1>obniz instant html</h1>
<button id="on">ON</button>
<button id="off">OFF</button>
<div id="print"></div>

<script>
let audioMax = 0;
let audioSum = 0;
let audioNum= 0;
  let lastVoltage = 0;
var obniz = new Obniz("OBNIZ_ID");
  let before = "off";
obniz.onconnect = async function () {
    obniz.io9.output(true);
      obniz.io10.output(false);
      obniz.io11.output(true);
  

  obniz.display.clear();
  obniz.display.print("Let's hit a hand.");
  var microphone = obniz.wired("AE_MICAMP", {vcc:0, gnd:1, out:2});
  
  
  microphone.onchange = function(voltage){
    lastVoltage = voltage;
    if(voltage > audioMax){
      audioMax = voltage;
    }
    audioSum += voltage;
    audioNum += 1;
  }


  var usb = obniz.wired("USB" , {gnd:11, vcc:8} );
  usb.off();
  setInterval(()=>{
      console.log(audioMax + ";"+(audioSum/audioNum).toFixed(2)+";"+(audioMax - (audioSum/audioNum)).toFixed(2) );
    
    if(audioMax - (audioSum/audioNum) > 0.8){
       if(before == "off"){
        obniz.display.clear();
          obniz.display.print("Nice!!");
       }
      before = "on";
        usb.on();
    }else{
         usb.off();
      if(before == "on"){
        obniz.display.clear();
          obniz.display.print("Let's hit a hand.");
      }
      before = "off";
    }
      
    audioMax = lastVoltage;
    audioSum = lastVoltage;
    audioNum = 1;
    
  },1000);
  
  
}

</script>
</body>
</html>

You will Get in Few Days

Circuit for Starter “obniz Board” is available on Amazon and other online stores.
You can get it at below

Our products and resellers

Forum

Visit our developer’s forum to discuss and discover technologies.

Forum

Contact

Feel free to contact out support and technical team.

Contact us