//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
|