找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1611|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

Servo+Knob Arduino代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1059445 發(fā)表于 2023-1-1 18:02 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
  1. /*
  2. Controlling a servo position using a potentiometer (variable resistor)

  3. modified on 8 Nov 2013
  4. */

  5. #include <Servo.h>

  6. Servo myservo;  // create servo object to control a servo

  7. int potpin = 0;  // analog pin used to connect the potentiometer
  8. int val;    // variable to read the value from the analog pin

  9. void setup() {
  10.   myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  11. }

  12. void loop() {
  13.   val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  14.   val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  15.   myservo.write(val);                  // sets the servo position according to the scaled value
  16.   delay(15);                           // waits for the servo to get there
  17. }


復(fù)制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表