/
RGB_Base.java
56 lines (44 loc) · 1.55 KB
/
RGB_Base.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.mandfer.sunfunpi4j;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.wiringpi.SoftPwm;
import java.awt.Color;
/**
*
* @author marcandreuf
*/
public abstract class RGB_Base extends BaseSketch {
public RGB_Base(GpioController gpio){
super(gpio);
}
public static final int LEDPINRED = 0;
public static final int LEDPINYELLOW = 1;
public static final int LEDPINGREEN = 1;
public static final int LEDPINBLUE = 2;
protected void ledInit(int ledPinA, int ledPinB) {
SoftPwm.softPwmCreate(ledPinA, 0, 100);
SoftPwm.softPwmCreate(ledPinB, 0, 100);
}
protected void ledInit(int ledPinA, int ledPinB, int ledPinC) {
ledInit(ledPinA, ledPinB);
SoftPwm.softPwmCreate(ledPinC, 0, 100);
}
protected void ledColorSet(Color color) {
ledColorSet(color.getRed(), color.getGreen(), color.getBlue());
}
protected void ledColorSet(int colorA, int colorB) {
SoftPwm.softPwmWrite(LEDPINRED, colorA);
SoftPwm.softPwmWrite(LEDPINGREEN, colorB);
}
protected void ledColorSet(int colorA, int colorB, int colorC) {
ledColorSet(colorA, colorB);
SoftPwm.softPwmWrite(LEDPINBLUE, colorC);
}
protected void turnLedOff(){
ledColorSet(Color.BLACK);
}
}