当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Processing GPIO.digitalRead()用法及代码示例


Processing, 类GPIO中的digitalRead()用法介绍。

用法

  • .digitalRead(pin)

参数

  • pin (int) 通用输入输出引脚

返回

  • int

说明

返回输入引脚的值,即 GPIO.HIGH (1) 或 GPIO.LOW (0)



在调用此函数之前,您需要通过调用 pinMode() 将引脚设置为输入。

例子

import processing.io.*;

// On the Raspberry Pi GPIO 4 is physical pin 7 on the header

void setup() {
  // INPUT_PULLUP enables the built-in pull-up resistor for this pin
  // left alone, the pin will read as HIGH
  // connected to ground (via e.g. a button or switch) it will read LOW
  GPIO.pinMode(4, GPIO.INPUT_PULLUP);
}

void draw() {
  if (GPIO.digitalRead(4) == GPIO.LOW) {
    // button is pressed
    fill(255);
  } else {
    // button is not pressed
    fill(204);
  }
  stroke(255);
  ellipse(width/2, height/2, width*0.75, height*0.75);
}

相关用法


注:本文由纯净天空筛选整理自processing.org大神的英文原创作品 GPIO.digitalRead()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。