MCPcopy Index your code
hub / github.com/processing/processing / digitalRead

Method digitalRead

java/libraries/io/src/processing/io/GPIO.java:177–201  ·  view source on GitHub ↗

Returns the value of an input pin @param pin GPIO pin @return GPIO.HIGH (1) or GPIO.LOW (0) @see pinMode @see digitalWrite @webref

(int pin)

Source from the content-addressed store, hash-verified

175 * @webref
176 */
177 public static int digitalRead(int pin) {
178 checkValidPin(pin);
179
180 if (NativeInterface.isSimulated()) {
181 return LOW;
182 }
183
184 String fn = String.format("/sys/class/gpio/gpio%d/value", pin);
185 byte in[] = new byte[2];
186 int ret = NativeInterface.readFile(fn, in);
187 if (ret < 0) {
188 throw new RuntimeException(NativeInterface.getError(ret));
189 } else if (1 <= ret && in[0] == '0') {
190 return LOW;
191 } else if (1 <= ret && in[0] == '1') {
192 return HIGH;
193 } else {
194 System.err.print("Read " + ret + " bytes");
195 if (0 < ret) {
196 System.err.format(", first byte is 0x%02x" + in[0]);
197 }
198 System.err.println();
199 throw new RuntimeException("Unexpected value");
200 }
201 }
202
203
204 /**

Callers

nothing calls this directly

Calls 7

checkValidPinMethod · 0.95
isSimulatedMethod · 0.95
readFileMethod · 0.95
getErrorMethod · 0.95
formatMethod · 0.65
printMethod · 0.65
printlnMethod · 0.45

Tested by

no test coverage detected