Introduction to the Buzzer

Introduction to the Buzzer

  1. Making a beep
  2. Changing tempo of beep
  3. Changing notes of beep
  4. Playing a Song

Before you start

How to enter data into Netbeans

How to create projects in Netbeans and transfer them into Robo JDE

How to Send a Project to the IntelliBrain-Bot

Basic Concepts of Programing

Using if/else statements

Using different types of Loops (For, While, Do, etc.)

Basic Methods


  • AnalogInput
  • .Sample()
  • Speaker
  • .Play()

Making A Simple Beep


We first need to create a new project named “Simple_Buzzer” then add the “RoboJDE.jar” file to the new project. If you do not remember how to do this, please refer back to “IDE Tutorial” for help on setting up a new project (//link).

After we create the new project, we need to import the libraries we need to be able to use the parts of the robot we are planning on using. These are added at the top of the project and your code should look like the following:


import com.ridgesoft.intellibrain.*;

import com.ridgesoft.io.*;

import com.ridgesoft.robotics.*;



public class Simple_Buzzer {



    public static void main(String[] args) {



        }

    }



  1. These imports are added to the top of every project so that you may call classes used by the robot
  2. You must ALWAYS include the necessary imports at the top of your program!

Inside the Class but before the first method we are going to create the display and the buzzer for our program to use by adding the following code:


private static Display screen = IntelliBrain.getLcdDisplay();

private static Speaker buzzer = IntelliBrain.getBuzzer();

private static int num1 = 0;

The variable num1 can be shared between methods and for our purposes is used to keep track of the number of times the loop has occurred (basically just counting). Your code should now look like:


import com.ridgesoft.intellibrain.*;

import com.ridgesoft.io.*;

import com.ridgesoft.robotics.*;



public class Simple_Buzzer {



private static Display screen = IntelliBrain.getLcdDisplay();

private static Speaker buzzer = IntelliBrain.getBuzzer();

private static int num1 = 0;



    public static void main(String[] args) {



        }

    }



We want to have the robot make a sound while we are counting. In order to accomplish this we are going to use a while loop. Instead of using a while(true) like we have previously though, we are going to compare the value of our num1 variable to another number of our choosing. Then inside the loop, we are going to use the num1 and remainder division to determine if a beep should play or not. We also will display if a beep is going to occur and the value of num1 to the LCD display. Add the following code inside the “main method”:


while(num1 <= 100){

 	if(num1%10 == 0){

                	buzzer.beep();

                	screen.print(0, "Beep");

            }else{

                	screen.print(0, "No Beep");

            }

            screen.print(1, " " + num1);

            num1++;

}

Your completed code should now look like this:


import com.ridgesoft.intellibrain.*;

import com.ridgesoft.io.*;

import com.ridgesoft.robotics.*;



public class Simple_Buzzer {



    private static Display screen = IntelliBrain.getLcdDisplay();

    private static Speaker buzzer = IntelliBrain.getBuzzer();

    private static int num1 = 0;



    public static void main(String[] args) {

        while(num1 <= 100){

            if(num1%10 == 0){

                buzzer.beep();

                screen.print(0, "Beep");

            }else{

                screen.print(0, "No Beep");

            }

            screen.print(1, " " + num1);

            num1++;

        }

    }

}

  1. The main method is where all the code is added to make the robot do what you want in our case we want it to beep
  2. For this code the robot should count to 100 and if the number it is currently on can be divided by 10 with 0 left over then the robot beeps otherwise it doesn’t
  3. "buzzer.beep();”: is used to make the buzzer make the beep
  4. “num1%10 == 0”: May look confusing but all this is saying is if you take num1 a divided it by 10 does it have a remainder? For example if num1 = 10 then 10/10 = 1 with 0 left over same idea

More Making a Simple Beep


  1. How many times does the Buzzer beep?
  2. Does the LCD display change?

Making Music & Changing Tempo

So we can make the buzzer beep. What about actually playing a song? Yes, you actually can do that and we're going to do it now! Let's create a new project named “Advanced_Buzzer” then add the “RoboJDE.jar” file to the new project. If you do not remember how to do this refer back to “IDE Tutorial” for help on setting up a new project. Go ahead and add the import statements we'll need as well.

 

import com.ridgesoft.intellibrain.*;

import com.ridgesoft.io.*;

import com.ridgesoft.robotics.*;



public class Advance_Buzzer {



public static void main(String[] args) {

  

}

}



Now, inside the Class but before the first method add the following code:


private static Display screen = IntelliBrain.getLcdDisplay();

private static Speaker buzzer = IntelliBrain.getBuzzer();

//Music notes

public static final int C4 = 262;

public static final int C4_SHARP = 277;

public static final int D4 = 294;

public static final int D4_SHARP = 311;

public static final int E4 = 330;

public static final int F4 = 349;

public static final int F4_SHARP = 370;

public static final int G4 = 392;

public static final int G4_SHARP = 415;

public static final int A4 = 440;

public static final int A4_SHARP = 466;

public static final int B4 = 494;

public static final int C5 = 523;

public static final int C5_SHARP = 554;

public static final int D5 = 587;

public static final int D5_SHARP = 622;

public static final int E5 = 659;

public static final int F5 = 698;

public static final int F5_SHARP = 740;

public static final int G5 = 784;

public static final int G5_SHARP = 831;

public static final int A5 = 880;

public static final int A5_SHARP = 932;

public static final int B5 = 988;

//Tempo

public static int Whole = 1200;

  1. Notice that all the music notes have to be defined one at a time.
  2. Also notice that they are called "final", this means that they cannot be changed later in the program - the values are fixed at this point
  3. For now the temp will be fixed, later on you will change this to a variable.
  4. Remember anything that starts with a // is a comment and is not necessary for the program to work properly.

In the “Main Method” add the following code:




        play_song();

    

There is not much in this main just a call to another method we will add more in here in a bit. In the play_song() method add the following code:

 

int Half = Whole / 2, Quarter = Whole / 4;

screen.print(0, "Little Lamb"); 

buzzer.play(B4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(G4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(B4, Half);

buzzer.play(A4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(A4, Half);

buzzer.play(B4, Quarter);

buzzer.play(D5, Quarter);

buzzer.play(D5, Half);

buzzer.play(B4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(G4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(B4, Quarter);

buzzer.play(A4, Quarter);

buzzer.play(G4, Whole);



  1. Next to every buzzer there is a “.play(note, speed)“ this is a preset operation by the Robo JDE
  2. When ever you want to play a song follow the template of “.play(note, speed)”
  3. Notice at the top the whole note is split into half and quarter notes

If all parts of the code where copied correctly it should look like this, make sure that your code looks the same:

 

import com.ridgesoft.intellibrain.*;

import com.ridgesoft.io.*;

import com.ridgesoft.robotics.*;



public class Advance_Buzzer {

private static Display screen = IntelliBrain.getLcdDisplay();

private static Speaker buzzer = IntelliBrain.getBuzzer();

//Music notes

public static final int C4 = 262;

public static final int C4_SHARP = 277;

public static final int D4 = 294;

public static final int D4_SHARP = 311;

public static final int E4 = 330;

public static final int F4 = 349;

public static final int F4_SHARP = 370;

public static final int G4 = 392;

public static final int G4_SHARP = 415;

public static final int A4 = 440;

public static final int A4_SHARP = 466;

public static final int B4 = 494;

public static final int C5 = 523;

public static final int C5_SHARP = 554;

public static final int D5 = 587;

public static final int D5_SHARP = 622;

public static final int E5 = 659;

public static final int F5 = 698;

public static final int F5_SHARP = 740;

public static final int G5 = 784;

public static final int G5_SHARP = 831;

public static final int A5 = 880;

public static final int A5_SHARP = 932;

public static final int B5 = 988;

//Tempo

public static int Whole = 1200;

public static void main(String[] args) {

              play_song();

}



	public static void play_song(){

		int Half = Whole / 2, Quarter = Whole / 4;

                             screen.print(0, "Little Lamb"); 

                             buzzer.play(B4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(G4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(B4, Half);

              buzzer.play(A4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(A4, Half);

              buzzer.play(B4, Quarter);

              buzzer.play(D5, Quarter);

              buzzer.play(D5, Half);

              buzzer.play(B4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(G4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(B4, Quarter);

              buzzer.play(A4, Quarter);

              buzzer.play(G4, Whole);

}

}



More Making Music & Changing Tempo

  1. What song is being played?
  2. What happens to the song if you change the tempo speed to a higher number?
  3. What about if you changed the tempo to a lower number?