2013-12-18 14:13:11 [显示全部楼层]
6069浏览
查看: 6069|回复: 0

[转载] [Arduino模块]SD20 伺服电机控制器

[复制链接]
[Arduino模块]
SD20 伺服电机控制器

电路示意:



代码示例:
  1. /*
  2. Example for SD20 servo driver chip. This will drive a servo from the
  3. first servo pin on the SD20 from 1ms to 2ms repeatedly. This also shows
  4. how to how to set use the expand mode to set custom ranges.
  5. By James Henderson, 2012.
  6. */
  7. #include <Wire.h>
  8. #define SD20ADDRESS 0x61                // Address of the SD20
  9. #define GETSOFT     (byte)0x00                    // Byte to get software version
  10. int softVer = 0;                        // Stores software version
  11. void setup(){
  12.   Wire.begin();                          
  13.   Serial.begin(9600);
  14.   Software();                           // Call function that reads software version
  15. // setExpand();                          // Calls function that sets expand mode values for servo movement
  16. }
  17. void loop(){
  18.   
  19.   for(int x = 1; x <= 20; x++){
  20.     Wire.beginTransmission(SD20ADDRESS);  // Send value of 254 to servo pins
  21.       Wire.write(x);
  22.       Wire.write(255);
  23.     Wire.endTransmission();
  24.     delayMicroseconds(100);
  25.   }
  26.     delay(500);
  27.   for(int x = 1; x <= 20; x++){
  28.     Wire.beginTransmission(SD20ADDRESS);  // Send value of 1 to servo pins
  29.       Wire.write(x);
  30.       Wire.write(1);
  31.     Wire.endTransmission();
  32.     delayMicroseconds(100);
  33.   }
  34.   delay(500);   
  35.       
  36. }
  37. /*void setExpand(){                     // Function to define custom settings for expanded mode
  38.   
  39.   Wire.beginTransmission(sd20Address);  // Send 43 to register 21
  40.   Wire.send(21);
  41.   Wire.send(43);
  42.   Wire.endTransmission();
  43.   
  44.   delayMicroseconds(70);                // Wait for SD20 to process the byte we just sent to it
  45.   
  46.   Wire.beginTransmission(sd20Address);  // Set offset
  47.   Wire.send(22);
  48.   Wire.send(0x03);
  49.   Wire.send(0x34);
  50.   Wire.endTransmission();
  51.   
  52.   delayMicroseconds(70);                // Wait for SD20 to process the byte we just sent to it
  53.   
  54. }
  55. */
  56. void Software(){                         // Function that reads software revision
  57.   Wire.beginTransmission(SD20ADDRESS);  
  58.   Wire.write(GETSOFT);                   // Send to the register that returns the software revision
  59.   Wire.endTransmission();               
  60.   
  61.   Wire.requestFrom(SD20ADDRESS, 1);      // Request 1 byte from SD20
  62.   while(Wire.available() > 0){           // While there are bytes to read
  63.   softVer = Wire.read();                 // Get software revision
  64.   }
  65.   Serial.println(softVer);               // Print software version to arduino serial monitor
  66. }
复制代码




您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail