Sets an output pin to be either high or low You need to set the pin to output by calling pinMode() before calling this function. Unlike on Arduino, it is not possible to set a input pin's internal pull-up resistor using this function. @param pin GPIO
(int pin, int value)
| 238 | * @webBrief Sets an output pin to be either high or low |
| 239 | */ |
| 240 | public static void digitalWrite(int pin, int value) { |
| 241 | checkValidPin(pin); |
| 242 | |
| 243 | String out; |
| 244 | if (value == LOW) { |
| 245 | // values are also stored in a bitmap to make it possible to set a |
| 246 | // default level per pin before enabling the output |
| 247 | values.clear(pin); |
| 248 | out = "0"; |
| 249 | } else if (value == HIGH) { |
| 250 | values.set(pin); |
| 251 | out = "1"; |
| 252 | } else { |
| 253 | System.err.println("Only GPIO.LOW and GPIO.HIGH, 0 and 1, or true and false, can be used."); |
| 254 | throw new IllegalArgumentException("Illegal value"); |
| 255 | } |
| 256 | |
| 257 | if (NativeInterface.isSimulated()) { |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | String fn = String.format("/sys/class/gpio/gpio%d/value", pin); |
| 262 | int ret = NativeInterface.writeFile(fn, out); |
| 263 | if (ret < 0) { |
| 264 | if (ret != -2) { // ENOENT, pin might not yet be exported |
| 265 | throw new RuntimeException(NativeInterface.getError(ret)); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | |
| 271 | /** |
nothing calls this directly
no test coverage detected