-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountdownTimer.java
64 lines (61 loc) · 2.58 KB
/
CountdownTimer.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
57
58
59
60
61
62
63
64
final GpioController gpio = GpioFactory.getInstance();
List<Pin> segmentsPins = new ArrayList(Arrays.asList(RaspiPin.GPIO_25,
RaspiPin.GPIO_02,
RaspiPin.GPIO_24,
RaspiPin.GPIO_23,
RaspiPin.GPIO_22,
RaspiPin.GPIO_21,
RaspiPin.GPIO_00,
RaspiPin.GPIO_07));
List<GpioPinDigitalOutput> segments = new ArrayList<>();
for (int i =0; i<segmentsPins.size(); i++){
segments.add(gpio.provisionDigitalOutputPin(segmentsPins.get(i), PinState.LOW));
}
List<Pin> digitsPin = new ArrayList(Arrays.asList(RaspiPin.GPIO_26,
RaspiPin.GPIO_05,
RaspiPin.GPIO_03,
RaspiPin.GPIO_01));
List<GpioPinDigitalOutput> digits = new ArrayList<>();
for (int i =0; i<digitsPin.size(); i++){
digits.add(gpio.provisionDigitalOutputPin(digitsPin.get(i), PinState.LOW));
}
Map<String, Integer[]> numbers = new HashMap();
numbers.put("0", new Integer[]{1,1,1,1,1,1,0});
numbers.put("1", new Integer[]{0,1,1,0,0,0,0});
numbers.put("2", new Integer[]{1,1,0,1,1,0,1});
numbers.put("3", new Integer[]{1,1,1,1,0,0,1});
numbers.put("4", new Integer[]{0,1,1,0,0,1,1});
numbers.put("5", new Integer[]{1,0,1,1,0,1,1});
numbers.put("6", new Integer[]{1,0,1,1,1,1,1});
numbers.put("7", new Integer[]{1,1,1,0,0,0,0});
numbers.put("8", new Integer[]{1,1,1,1,1,1,1});
numbers.put("9", new Integer[]{1,1,1,1,0,1,1});
try{
Calendar calendar = Calendar.getInstance();
String time;
while (true){
calendar = Calendar.getInstance();
time = new SimpleDateFormat("HHmm").format(calendar.getTime());
for(int i=0; i<digits.size(); i++){
for(int j=0; j<segments.size()-1; j++){
segments.get(j).low();
if(numbers.get(String.valueOf(time.charAt(i)))[j] == 1){
segments.get(j).high();
}
if(i==1){
segments.get(7).high();
}else{
segments.get(7).low();
}
}
digits.get(i).high();
}
}
}catch (Exception e){
e.printStackTrace();
}
if(i==1 && seconds%2==0){
segments.get(7).high();
}else{
segments.get(7).low();
}