如何为Arduino编写C ++库? [英] How to write a C++ library for Arduino?
问题描述
我为我的Arduino编写了一个C ++库来控制软盘驱动器步进电机,但是当我编译它时会显示此错误消息
错误:从'FLOP *'转换要求非标量类型'FLOP'
这是头文件
#ifndef FLOP_h
#define FLOP_h
#include Arduino.h
class FLOP {
public :
FLOP ( int steppin, int dirpin);
void 顺时针( int 步骤);
void 逆时针( int 步骤);
};
#endif
这里是源文件
< pre lang =c ++>< pre lang = c ++> #include FLOP.h
#include Arduino.h
public FLOP :: FLOP(< span class =code-keyword> int steppin, int dirpin){
pinMode(steppin,OUTPUT);
pinMode(dirpin,OUTPUT);
int step_pin = steppin;
int dir_pin = dirpin;
}
void FLOP ::顺时针( int 步骤){
digitalWrite(dir_pin,HIGH);
for ( int i = 0 ; i< steps; i ++){
digitalWrite(step_pin,LOW);
delayMicroseconds( 100 );
digitalWrite(step_pin,HIGH);
delayMicroseconds( 100 );
}
digitalWrite(step_pin,LOW);
}
void FLOP :: counterclockwise( int 步骤){
digitalWrite(dir_pin,LOW);
for ( int i = 0 ; i< steps; i ++){
digitalWrite(step_pin,LOW);
delayMicroseconds( 100 );
digitalWrite(step_pin,HIGH);
delayMicroseconds( 100 );
}
digitalWrite(step_pin,LOW);
}
成员变量step_pin
和dir_pin
缺少。所以将它们添加到你的班级:
class FLOP {
public :
FLOP( int steppin, int dirpin) ;
void 顺时针( int 步骤);
void 逆时针( int 步骤);
受保护:
int dir_pin;
int step_pin;
};
并将构造函数更改为:
FLOP :: FLOP( int steppin,int dirpin){
pinMode(steppin,OUTPUT);
pinMode(dirpin,OUTPUT);
step_pin = steppin;
dir_pin = dirpin;
}
I wrote a C++ library for my Arduino to control a floppy drive stepper motor, but when i compile it shows this error message
error: conversion from 'FLOP*' to non-scalar type 'FLOP' requested
Here is the header file
#ifndef FLOP_h
#define FLOP_h
#include "Arduino.h"
class FLOP{
public:
FLOP(int steppin,int dirpin);
void clockwise(int steps);
void counterclockwise(int steps);
};
#endif
and Here is the Source file
<pre lang="c++">#include "FLOP.h"
#include "Arduino.h"
public FLOP::FLOP(int steppin , int dirpin){
pinMode(steppin,OUTPUT);
pinMode(dirpin,OUTPUT);
int step_pin = steppin;
int dir_pin = dirpin;
}
void FLOP::clockwise(int steps){
digitalWrite(dir_pin,HIGH);
for(int i=0; i < steps;i++){
digitalWrite(step_pin,LOW);
delayMicroseconds(100);
digitalWrite(step_pin,HIGH);
delayMicroseconds(100);
}
digitalWrite(step_pin,LOW);
}
void FLOP::counterclockwise(int steps){
digitalWrite(dir_pin,LOW);
for(int i=0; i < steps;i++){
digitalWrite(step_pin,LOW);
delayMicroseconds(100);
digitalWrite(step_pin,HIGH);
delayMicroseconds(100);
}
digitalWrite(step_pin,LOW);
}
The member variablesstep_pin
anddir_pin
are missing. So add them to your class:
class FLOP{ public: FLOP(int steppin,int dirpin); void clockwise(int steps); void counterclockwise(int steps); protected: int dir_pin; int step_pin; };
and change your constructor to:
FLOP::FLOP(int steppin , int dirpin){ pinMode(steppin,OUTPUT); pinMode(dirpin,OUTPUT); step_pin = steppin; dir_pin = dirpin; }
这篇关于如何为Arduino编写C ++库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!