import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.GpioPin;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class MotorPinTest
{

    public static void main (String args[]){
       GpioController gpio = GpioFactory.getInstance();
        
        
       final GpioPinDigitalOutput pin1 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW);
       final GpioPinDigitalOutput pin2 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_26, "MyLED", PinState.LOW);
       
       final GpioPinDigitalOutput pin3 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_23, "MyLED", PinState.LOW);
       final GpioPinDigitalOutput pin4 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_24, "MyLED", PinState.LOW);
       
       
       // play 
       
       int i = 0;
       while (i < 10){
           // forward
           pin1.high();
           pin2.low();
           pin3.high();
           pin4.low();           
           sleep(2000);
           
           // stop
           pin1.low();
           pin2.low();
           pin3.low();
           pin4.low();
           sleep(2000);  
           
           // backward
           pin1.low();
           pin2.high();
           pin3.low();
           pin4.high();

           sleep(2000);           
           
           // stop
           pin1.low();
           pin2.low();
           pin3.low();
           pin4.low();
           
           i++;
           sleep(2000);
        }
        gpio.shutdown();
        gpio.unprovisionPin(new GpioPin[]{pin1,pin2,pin3,pin4});
    }
    
    public static void sleep(long s){
        try{
            Thread.sleep(s);
        } catch (Exception e) {
            // do nothing shit happends
        }
    }
}

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert