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

Method digitalWrite

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

Sets an output pin to be either high or low @param pin GPIO pin @param value GPIO.HIGH (1) or GPIO.LOW (0) @see pinMode @see digitalRead @webref

(int pin, int value)

Source from the content-addressed store, hash-verified

210 * @webref
211 */
212 public static void digitalWrite(int pin, int value) {
213 checkValidPin(pin);
214
215 String out;
216 if (value == LOW) {
217 // values are also stored in a bitmap to make it possible to set a
218 // default level per pin before enabling the output
219 values.clear(pin);
220 out = "0";
221 } else if (value == HIGH) {
222 values.set(pin);
223 out = "1";
224 } else {
225 System.err.println("Only GPIO.LOW and GPIO.HIGH, 0 and 1, or true and false, can be used.");
226 throw new IllegalArgumentException("Illegal value");
227 }
228
229 if (NativeInterface.isSimulated()) {
230 return;
231 }
232
233 String fn = String.format("/sys/class/gpio/gpio%d/value", pin);
234 int ret = NativeInterface.writeFile(fn, out);
235 if (ret < 0) {
236 if (ret != -2) { // ENOENT, pin might not yet be exported
237 throw new RuntimeException(NativeInterface.getError(ret));
238 }
239 }
240 }
241
242
243 /**

Callers

nothing calls this directly

Calls 8

checkValidPinMethod · 0.95
isSimulatedMethod · 0.95
writeFileMethod · 0.95
getErrorMethod · 0.95
setMethod · 0.65
formatMethod · 0.65
clearMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected