救救孩子吧,这总线舵机的库函数一直不好使,要崩了-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 547|回复: 2

[未解决] 救救孩子吧,这总线舵机的库函数一直不好使,要崩了

[复制链接]
发表于 2021-12-11 21:28 | 显示全部楼层 |阅读模式

//DUOJI.h//
#ifndef DUOJI_H
#define DUOJI_H

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif
class DUOJI {
public:
        DUOJI();
        void Dong(uint8_t a, uint8_t b);
private:
        uint8_t        checksum(uint8_t* buf, uint8_t sz);
        void serial_write( uint8_t* send, uint8_t ssz);
        uint8_t a;
        uint8_t b;
        uint8_t* send;
        uint8_t ssz;
        uint8_t* buf;
        uint8_t sz;
        uint16_t sum;
};
#if 0
#else
extern uint8_t checksum(uint8_t* buf, uint8_t sz);
extern void serial_write( uint8_t* send, uint8_t ssz);
extern void Dong(uint8_t a,        uint8_t b);
#endif

#endif




                                                              //DUOJI.cpp//
#if  ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif
#include"DUOJI.h"
void serial_write( uint8_t* send, uint8_t ssz);
void Dong(uint8_t a, uint8_t b);
uint8_t checksum(uint8_t* buf, uint8_t sz);
static uint8_t        cmd[10] = { 0xFA, 0xAF, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0xED };

void DUOJI:ong(uint8_t a,        uint8_t b)
{
  cmd[2]=a;  
  cmd[4]=b;
  cmd[8] = checksum(&cmd[2], 6);        
  serial_write( cmd, 10);
}
void DUOJI::serial_write( uint8_t* send, uint8_t ssz)
{
Serial.begin(115200, SERIAL_8N1);
  delayMicroseconds(50);

  for(uint8_t i=0; i<ssz; i++)
  {
    Serial.write(send[i]);
    Serial.flush();
  }
}
uint8_t DUOJI::checksum(uint8_t* buf, uint8_t sz)
{
  {
    uint16_t sum = 0;
    for(uint8_t i=0; i<sz; i++)
      sum += buf[i];
    return (uint8_t)(sum&0xff);
  }
}



程序
#include <DUOJI.h>
#define Tx 1
void setup() {
  // put your setup code here, to run once:
Dong(0x01,0x3c);

}

void loop() {
  // put your main code here, to run repeatedly:

}

报错
undefined reference to `Dong(unsigned char, unsigned char)'

collect2.exe: error: ld returned 1 exit status
exit status 1




发表于 2021-12-11 22:37 | 显示全部楼层
实在不行别用库了。。。。自己串口写一个就行了
 楼主| 发表于 2021-12-12 10:33 | 显示全部楼层
XlinliY.Zhang 发表于 2021-12-11 22:37
实在不行别用库了。。。。自己串口写一个就行了

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

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 18:50 , Processed in 0.085265 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表