欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

arduino控制單舵機(jī)(180度)2連續(xù)運(yùn)動

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:312827 發(fā)表于 2018-4-21 08:28 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式
金工實(shí)習(xí)     控制小車

單片機(jī)源程序如下:
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial mySerial(0, 1);       // RX, TX
  3. #include <Servo.h>
  4. Servo myservo;                       // create servo object to control a servo
  5. int pos=60;  
  6. int p1=2;                       // variable to store the servo position
  7. char val='/';
  8. void setup()
  9. {
  10.     Serial.begin(9600);
  11. myservo.attach(p1);       // attaches the servo on pin 2 to the servo object                     
  12.     myservo.write(pos);       //初始化所有舵機(jī)位置,防止通電抖動。
  13.     delay(1000);
  14.     myservo.detach();

  15. }
  16. void loop()                     // run over and over
  17. {
  18.     val=Serial.read();
  19.     if(val=='1')
  20.     {  
  21.       myservo.attach(p1);       // attaches the servo on pin 2 to the servo object
  22.        for(inti=1;i<=30;i++)     // goes from 60 degrees to 30 degrees
  23.        {               
  24.          pos--;                 
  25.          myservo.write(pos);    // tell servo to go to position in variable 'pos'
  26.          delay(15);           // waits 15ms for the servo to reach the position
  27.        }
  28.        If(pos==0)pos=180;
  29.        myservo.detach();
  30.        val='11';
  31.     }
  32.     if(val=='2')
  33.    {
  34.        myservo.attach(p1);
  35.        for(pos=30;pos<=60;pos+= 1)  // goes from 30 degrees to 60 degrees
  36.        {                            // in steps of 1 degree
  37.          myservo.write(pos);       // tell servo to go to position in variable 'pos'
  38.          delay(15);                // waits 15ms for the servo to reach the position
  39.        }
  40.        myservo.detach();
  41.        val='22';
  42.    }
  43. }
復(fù)制代碼

所有資料51hei提供下載:
遙控單舵機(jī)(180度)2連續(xù)運(yùn)動20171227.docx (16.04 KB, 下載次數(shù): 6)


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

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

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