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


Processing SoftwareServo.attached()用法及代码示例


Processing, 类SoftwareServo中的attached()用法介绍。

用法

  • .attached()

返回

  • boolean

说明

返回伺服电机是否连接到引脚

例子

import processing.io.*;
SoftwareServo servo;

void setup() {
  servo = new SoftwareServo(this);
  servo.attach(4);

  // On the Raspberry Pi, GPIO 4 is pin 7 on the pin header,
  // located on the fourth row, above one of the ground pins
}

void draw() {
  // we don't go right to the edge to prevent
  // making the servo unhappy
  float angle = 90 + sin(frameCount / 100.0)*85;
  servo.write(angle);
}

void keyPressed() {
  // press a key to release or re-attach the motor
  if (servo.attached()) {
    servo.detach();
  } else {
    servo.attach(4);
  }
}

相关用法


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