Repository navigation
Expand file tree
/
Copy pathPiControl.java
More file actions
74 lines (64 loc) · 1.92 KB
/
Copy pathPiControl.java
File metadata and controls
74 lines (64 loc) · 1.92 KB
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
65
66
67
68
69
70
71
72
73
74
/*
* **********************************************************************
* Pi controlled functions for the spectrum analyzer
* Button presses passed back to a calling routine (maybe)
* Camera takes pictures
* **********************************************************************
*
* Copyright (C) 2015 Center for Applied Cytometry
*
* Maintenance history
* Date Author Change
* 2025/01/22 PLS Rewrite for Pi4, only white light for Analyze2 testing (main)
* Suspect this is part of auto detect of spectrum location
*/
import com.pi4j.Pi4J;
import com.pi4j.io.gpio.digital.*;
import com.pi4j.context.Context;
public class PiControl
{static boolean tracer = false;
static final int whiteLight = 2; // GPIO pin for white LED, header pin 3
static DigitalOutput whitePin;
static Context pi4j;
/*
public PiControl()
{PiControl(false);
}
*/
public PiControl(boolean b)
{
tracer = b;
pi4j = Pi4J.newAutoContext(); // setup I/O environment
setupIOPins();
}
private void setupIOPins()
{if (tracer) System.out.println("PiC.setupIOPins()");
// setup output pins
var ledConfig = DigitalOutput.newConfigBuilder(pi4j)
.initial(DigitalState.HIGH)
.shutdown(DigitalState.HIGH)
// .provider(mock) // should allow running on non-pi hardware
;
whitePin = pi4j.create(ledConfig.address(2).id("white")); // 3
}
public void cuvetteLightOff() // LEDs on a relay, high output turns off
{if (tracer) System.out.println("PiC.cuvetteLightOn()");
whitePin.high();
}
public void cuvetteLightOn()
{if (tracer) System.out.println("PiC.cuvetteLightOff()");
whitePin.low();
}
public void done()
{if (tracer) System.out.println("PiC.done()");
pi4j.shutdown();
}
public static void main(String[] args) throws InterruptedException
{PiControl pic = new PiControl(true);
pic.cuvetteLightOn();
System.out.print("Press Enter to turn off lights");
String input = System.console().readLine();
pic.cuvetteLightOff();
pic.done();
}
}