krotedu.blogg.se

Example bluej program using gpio
Example bluej program using gpio








  1. Example bluej program using gpio how to#
  2. Example bluej program using gpio install#
  3. Example bluej program using gpio code#
  4. Example bluej program using gpio download#

In the Controller class, the LED object is called 'led': it is already there for you!.

Example bluej program using gpio code#

  • To edit the Controller class, double click on the "Controller" yellow box and you will see the source code for the Controller class.
  • In the Controller class, change the body of the method "void turnLEDOn()" to call the method which will turn the LED on, and likewise change the method "void turnLEDOff()" in the same class to turn the LED off.
  • Exercise 1.2: You can write code in the Controller class to do what you have just done interactively.
  • Exercise 1.1: You have turned the LED on.
  • To see them just double click in the LED class (yellow box) and its documentation (javadoc) will show up: Figure 9: The Javadoc for the LED class. Tip: The LED Class contains its own documentation showing all the available methods and a brief description of each of them. We didn't need to do that because the default gpio number is the gpio number 6, where we connected our LED. If you look at Figure 6, you can see that we can also create a LED specifying a gpio number.

    example bluej program using gpio

    (It might take a moment the first time, as all the behind-the-scenes connections are made). Void on() Figure 8: The pop-up with the list of operations on "lED1". To turn the LED on, right-click on the "lED1" instance and select: This object is the Java representation of the real LED connected to the Raspberry Pi. This rectangular red icon represents the "lED1" object. You will see a red rectangle on the bottom left of the BlueJ window named "lED1": Figure 7: An instance of LED on the object bench. To start, right-click on the LED class and from the pop-up menu, choose: new LED() Figure 6: Creating an instance of LED.īlueJ will ask for the "name of the instance": the suggested name is good for now. The Button and ButtonListener classes will be described in Part 2 of this tutorial.īefore we start to write code, we'll see how the LED class affects the real LED by using BlueJ to control it directly. The Controller class is where you will write your own code. The LED, Button and ButtonListener classes are already made and you can use them in the following exercises, but do not change them. The LED class represents the real LED connected to the Raspberry Pi. Your screen should look like this: Figure 5: The LED and Button project open in BlueJ.Įach of the yellow boxes in the BlueJ screen above is a Java class. Don't forget to get the legs of the LED the right way round!įigure 4: Using a breadboard (click for larger picture). If you have a breadboard of any size available, we recommend using it to build the circuit. Here is what your circuit should look like: Figure 3: Connection to the Raspberry Pi. However, the assignment for those pins present on both models (B and B+) will still be the same as described here and the project should work without change. Note: If you have a Raspberry Pi model B+, you will have more than 26 pins. The Black wire should then be connected to the pin marked 20 (Ground) on your Pi and the red wire should be connected to the pin marked 22 (GPIO6): Figure 2: The Raspberry Pi Pins. The other leg of the resistor should be connected to the other wire (the red one), as in the following picture: Figure 1: connecting the LED to the resistor (click for larger picture).

    example bluej program using gpio

    The resistor is used to limit the current flowing and prevent the LED from burning out. The short leg (ground terminal) should be connected directly to the black wire and the longer leg should be connected to your resistor.

    example bluej program using gpio

    It will have one long leg and one shorter one.

  • 1 Resistor (any value between 270Ω to 330Ω)Īn LED is a component that emits light whenever there is a current flowing through it.
  • Example bluej program using gpio download#

    This tutorial will make use of the project LEDButton, which you should download and open in BlueJ running on the Raspberry Pi.

    example bluej program using gpio

    In this section, we will connect a LED to a Raspberry Pi and turn it on and off by direct object manipulation using BlueJ.

    Example bluej program using gpio install#

    If you have not got BlueJ installed in your Raspberry Pi, please install it by following the instructions here. In the first we'll look at output and lighting an LED, in the second we'll look at input from a button.

    Example bluej program using gpio how to#

    It is not intended to be a complete description of how to use the pins: for that, see the sections called Under the Hood. This tutorial describes how to use BlueJ on the Raspberry Pi to to interact with simple electronics using the Pi's GPIO pins (General-Purpose Input/Output pins).










    Example bluej program using gpio