NanoPi NEO Air - pi4j로 PWM 제어

OS/Raspberry Pi 2017.03.22 23:08 Posted by 파란크리스마스

NanoPi NEO Air - pi4j로 PWM 제어

NanoPi NEO Air는 하나의 PWM만 지원

배선

Java 소스

import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.NanoPiNEOAirGpioProvider;
import com.pi4j.wiringpi.Gpio;
import com.pi4j.wiringpi.SoftPwm;

public class SG90PWMMain {

	private static int PIN_NUMBER = 1;

	public static void main(String[] args) throws Exception {
		//
		//GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
		//GpioFactory.setDefaultProvider(new OrangePiPc2GpioProvider());
		GpioFactory.setDefaultProvider(new NanoPiNEOAirGpioProvider());

		// initialize wiringPi library, this is needed for PWM
		Gpio.wiringPiSetup();

		// softPwmCreate(int pin, int value, int range)
		// the range is set like (min=0 ; max=100)
		SoftPwm.softPwmCreate(PIN_NUMBER, 0, 50);
		int counter = 0;
		while (counter < 3) {
			// fade LED to fully ON
			for (int i = 0; i <= 100; i++) {
				// softPwmWrite(int pin, int value)
				// This updates the PWM value on the given pin. The value is
				// checked to be in-range and pins
				// that haven't previously been initialized via softPwmCreate
				// will be silently ignored.
				SoftPwm.softPwmWrite(PIN_NUMBER, i);
				Thread.sleep(25);
			}
			// fade LED to fully OFF
			for (int i = 100; i >= 0; i--) {
				SoftPwm.softPwmWrite(PIN_NUMBER, i);
				Thread.sleep(25);
			}
			counter++;
		}
	}

}

실행

# java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar SG90PWMMain

실행 영상

저작자 표시
신고


 

티스토리 툴바