티스토리 뷰

OS/Orange PI

Orange PI Zero - pi4j로 PWM 제어

파란크리스마스 2017. 3. 25. 12:10
728x90

Orange PI Zero - pi4j로 PWM 제어

Orange PI Zero는 하나의 PWM만 지원

배선

Java 소스

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

public class SG90PWMMain {

	private static int PIN_NUMBER = 7;

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

		// 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++;
		}
	}

}

실행

$ sudo java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar SG90PWMMain

실행 영상

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함