Close
0%
0%

Graphical roulette with obniz

If you press the button, the roulette starts rotating. If you press again, the roulette stops rotating and beeps!

Public Chat
Similar projects worth following
109 views
0 followers
I have made a graphical roulette. If you press the button, the roulette starts rotating. If you press again, the roulette stops rotating and beeps!

For the detailed instruction and program, please click here.

  • 1 × obniz

  • 1
    Circit

    It is only wired speaker and button.

    The pin no of wired are written on program.

    button = obniz.wired("Button", {signal:6 , gnd:7 });
    speaker = obniz.wired("Speaker", {signal:0 , gnd: 1});
    
  • 2
    Rotate image

    On HTML, you can use "css transform". For example , this is the code of rotate image 90 degree.

    document.getElementById("roulette").style = "transform:rotate(90deg);";

    To start and stop rotate slowly, add a var speed for rotate degree per frame.

    let speed = 0;
      let deg = 0;
      function rotate(){
        deg += speed;
          document.getElementById("roulette").style = "transform:rotate("+deg+"deg);";
    
      }
      setInterval(rotate,10);
  • 3
    Beep

    Do you want to beep on the roulette no change? With this, you can beep on 440Hz 10ms.

    speaker.play(440);
          await obniz.wait(10);
          speaker.stop();

    This is how to know on change of roulette no.

    if( Math.floor((deg + speed) / (360/7.0)) -  Math.floor(deg / (360/7.0)) >= 1){
          onRouletteChange();
    }

     So, this is the code of rotate and beep.

      let speed = 0;
      let deg = 0;
      function rotate(){
        //on change value
        if( Math.floor((deg + speed) / (360/7.0)) -  Math.floor(deg / (360/7.0)) >= 1){
          onRouletteChange();
        }
        deg += speed;
          document.getElementById("roulette").style = "transform:rotate("+deg+"deg);";
    
      }
      setInterval(rotate,10);
    
      async function onRouletteChange(){
        if(!speaker){return;}
          speaker.play(440);
          await obniz.wait(10);
          speaker.stop(); 
      }

View all 4 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates