當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。