Skip to content

alejojperez/pi-gpio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pi-gpio

A package to control the gpio pins in a raspberry pi.

Use Example

Using a single pin
public class Main
{
    public static void main(String[] args)
    {
        Pin pin;
        IFileLogger logger = new FileLogger();

        try {
            pin = new Pin(11);
            pin.registerLogger(logger);

            pin.initialize();
            pin.setDirection(Pin.GPIO_OUT);
            pin.setValue(Pin.GPIO_ON);

            Thread.sleep(3000);

            pin.setValue(Pin.GPIO_OFF);
            pin.destroy();

        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Using the pins controller
public class Main
{
    public static void main(String[] args)
    {
        IGPIOController controller = GPIOController.getInstance();
        IFileLogger logger = new FileLogger();

        try {
            controller.addPin("red-pin", 11).get("red-pin").registerLogger(logger).initialize().setDirection(Pin.GPIO_OUT);
            controller.addPin("blue-pin", 12).get("blue-pin").registerLogger(logger).initialize().setDirection(Pin.GPIO_OUT);
            controller.addPin("yellow-pin", 13).get("yellow-pin").registerLogger(logger).initialize().setDirection(Pin.GPIO_OUT);

            controller.get("red-pin").setValue(Pin.GPIO_ON);
            Thread.sleep(3000);
            controller.get("red-pin").setValue(Pin.GPIO_OFF);

            controller.get("blue-pin").setValue(Pin.GPIO_ON);
            Thread.sleep(3000);
            controller.get("blue-pin").setValue(Pin.GPIO_OFF);

            controller.get("yellow-pin").setValue(Pin.GPIO_ON);
            Thread.sleep(3000);
            controller.get("yellow-pin").setValue(Pin.GPIO_OFF);

            controller.flushPins();

        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Apache License

Version 2.0, January 2004
http://www.apache.org/licenses

About

A package to control a raspberry gpio pins.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages