[Arduino模块]
SD20 伺服电机控制器
电路示意:
代码示例:
- /*
- Example for SD20 servo driver chip. This will drive a servo from the
- first servo pin on the SD20 from 1ms to 2ms repeatedly. This also shows
- how to how to set use the expand mode to set custom ranges.
-
- By James Henderson, 2012.
- */
-
- #include <Wire.h>
-
- #define SD20ADDRESS 0x61 // Address of the SD20
- #define GETSOFT (byte)0x00 // Byte to get software version
-
- int softVer = 0; // Stores software version
-
- void setup(){
- Wire.begin();
- Serial.begin(9600);
- Software(); // Call function that reads software version
- // setExpand(); // Calls function that sets expand mode values for servo movement
- }
-
- void loop(){
-
- for(int x = 1; x <= 20; x++){
- Wire.beginTransmission(SD20ADDRESS); // Send value of 254 to servo pins
- Wire.write(x);
- Wire.write(255);
- Wire.endTransmission();
- delayMicroseconds(100);
- }
- delay(500);
- for(int x = 1; x <= 20; x++){
- Wire.beginTransmission(SD20ADDRESS); // Send value of 1 to servo pins
- Wire.write(x);
- Wire.write(1);
- Wire.endTransmission();
- delayMicroseconds(100);
- }
- delay(500);
-
- }
-
- /*void setExpand(){ // Function to define custom settings for expanded mode
-
- Wire.beginTransmission(sd20Address); // Send 43 to register 21
- Wire.send(21);
- Wire.send(43);
- Wire.endTransmission();
-
- delayMicroseconds(70); // Wait for SD20 to process the byte we just sent to it
-
- Wire.beginTransmission(sd20Address); // Set offset
- Wire.send(22);
- Wire.send(0x03);
- Wire.send(0x34);
- Wire.endTransmission();
-
- delayMicroseconds(70); // Wait for SD20 to process the byte we just sent to it
-
- }
- */
- void Software(){ // Function that reads software revision
- Wire.beginTransmission(SD20ADDRESS);
- Wire.write(GETSOFT); // Send to the register that returns the software revision
- Wire.endTransmission();
-
- Wire.requestFrom(SD20ADDRESS, 1); // Request 1 byte from SD20
- while(Wire.available() > 0){ // While there are bytes to read
- softVer = Wire.read(); // Get software revision
- }
- Serial.println(softVer); // Print software version to arduino serial monitor
- }
复制代码
|
|
|
|
|
|