Search in sources :

Example 1 with PWMChannel

use of com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device.PWMChannel in project robo4j by Robo4J.

the class PWMPCA9685DeviceTest method main.

public static void main(String[] args) throws IOException, InterruptedException {
    System.out.println("Creating device...");
    PWMPCA9685Device device = new PWMPCA9685Device();
    device.setPWMFrequency(SERVO_FREQUENCY);
    Servo servo0 = new Servo(device.getChannel(0));
    Servo servo1 = new Servo(device.getChannel(1));
    PWMChannel motor0 = device.getChannel(2);
    PWMChannel motor1 = device.getChannel(3);
    System.out.println("Setting start conditions...");
    servo0.setInput(0);
    servo1.setInput(0);
    motor0.setPWM(0, MOTOR_MIN);
    motor1.setPWM(0, MOTOR_MIN);
    System.out.println("Press enter to run loop!");
    System.in.read();
    System.out.println("Running perpetual loop...");
    while (true) {
        servo0.setInput(-1);
        servo1.setInput(-1);
        motor0.setPWM(0, MOTOR_MEDIUM);
        motor1.setPWM(0, MOTOR_MEDIUM);
        Thread.sleep(500);
        servo0.setInput(1);
        ;
        servo1.setInput(1);
        ;
        motor0.setPWM(0, MOTOR_MAX);
        motor1.setPWM(0, MOTOR_MAX);
        Thread.sleep(500);
        servo0.setInput(0);
        servo1.setInput(0);
        motor0.setPWM(0, MOTOR_MIN);
        motor1.setPWM(0, MOTOR_MIN);
        Thread.sleep(1000);
    }
}
Also used : Servo(com.robo4j.hw.rpi.i2c.pwm.Servo) PWMPCA9685Device(com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device) PWMChannel(com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device.PWMChannel)

Aggregations

PWMPCA9685Device (com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device)1 PWMChannel (com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device.PWMChannel)1 Servo (com.robo4j.hw.rpi.i2c.pwm.Servo)1