Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C++
#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
C++
<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);
}
Posted

1 solution

The member variables step_pin and dir_pin are missing. So add them to your class:
C#
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;
}
 
Share this answer
 
Comments
Fraol Gelana 2-Jun-15 3:52am    
Thank You Very much!, i corrected many of my errors but still this error message keeps appearing error: conversion from 'FLOP*' to non-scalar type 'FLOP' requested
Jochen Arndt 2-Jun-15 4:08am    
You should show us the source code line where the error occurs.
Fraol Gelana 2-Jun-15 4:41am    
When i include my library into a sketch as such for example this
#include <flop.h>
FLOP flop = new FLOP(9 ,8);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
flop.clockwise(20);
delay(5000);
flop.counterclockwise(20);
delay(5000);
}
when i compile this sketch it displays error message
error: conversion from 'FLOP*' to non-scalar type 'FLOP' requested
Jochen Arndt 2-Jun-15 4:48am    
The new operator allocates heap memory and returns a pointer to that memory. So you must use:
FLOP *flop = new FLOP(9, 8);
and use it as pointer:
flop->clockwise(20);

Alternatively create it on the stack:
FLOP flop(9, 8);
flop.clockwise(20);
Fraol Gelana 2-Jun-15 6:13am    
Wow!!, That fixed the Problem!!!
Thank You Very Much from Ethiopia!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900