zoukankan      html  css  js  c++  java
  • Arduino舵机控制

    普通舵机有3根线:GND(黑)、VCC(红)、Signal(黄)

    红色的是电源正极,黑色的是电源负极,白色的是信号线。有些舵机线是红棕橘三色,分别对应红黑白。
    #include <Servo.h>
    
    Servo myservo; 
     
    int pos = 90;  
    
    
    void setup() {
      
      Serial.begin(9600);
        pinMode(4, OUTPUT);
        pinMode(5, OUTPUT);
         myservo.attach(9);  
     
    }
     

    void loop() {
     
       
       char val = Serial.read(); 
      
      
     
    
      if(val=='z')
     
    {   
        pos+=30;                                 // in steps of 1 degree 
        myservo.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(150);                       // waits 15ms for the servo to reach the position 
      
        Serial.println(" servo_right");    
     } 
     
    if(val=='x')
    {
       pos-=30;                              // in steps of 1 degree 
        myservo.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(150);                       // waits 15ms for the servo to reach the position 
      
       Serial.println(" servo_left");
    }
  • 相关阅读:
    什么是web框架
    编写CGI程序步骤
    web开发 c/s结构 和 b/s结构
    python自带的web服务器
    自制计算器
    条件判断
    模版继承
    参数传递
    异常处理
    【uoj#244】[UER #7]短路 CDQ分治+斜率优化dp
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/5571484.html
Copyright © 2011-2022 走看看