/*Written and created by Daneo*/
#include "Wprogram.h"
#include "Mosfets.h"
int Stap[6] = { B001101 , B110001 , B000111 , B010011 , B001101 , B011100}; //Outputs on PORTB to control MOSFET's
int Time = 50; //Initial time in ms the arduino will do
int Correct_mode; //0 will be defined as autorun, initial step, 1 as manual
int Mode = 0; //Autorun mode
int Manual_step; //This variable will hold the step that the user wants the arduino to be in.
void Mosfets::Init()
{
Serial.begin(9600);
DDRB = B111111;
}
void Mosfets::Autorun()
{
for(int i = 0; i <= 5; i++)
{
Correct_mode = Mode_check(0);
if(Correct_mode == 1)
Output(i);
}
}
void Mosfets::Manual()
{
Correct_mode = Mode_check(1);
if(Correct_mode == 1)
Output(Manual_step);
}
void Mosfets::Change_mode(int data)
{
int temp_save = data;
int confirmation;
Serial.println("Do you want to modify the step?(1/0)");
Serial.flush();
while(!Serial.available()); // Wait for answer
confirmation = Serial.read();
Serial.flush();
if(confirmation == 1)
{
Serial.println("What step do you want to program? Enter 8 to return to automatic.");
while(!Serial.available()); // Wait for answer
int temp_step = Serial.read();
if(temp_step > 0 && temp_step <= 5)
{
Mode = 1;
Manual_step = temp_step;
}
else if(temp_step == 8)
Mode = 0;
Serial.flush();
Serial.println("Succesfully changed Mode to " + Mode);
}
else if(confirmation == 0)
{
Serial.println("Do you want to adjust the time/cycle? (1/0)");
while(!Serial.available());
confirmation = Serial.read();
if(confirmation == 1 ) //It seems he does
{
Serial.println("Enter the value you want to adjust the time with (if necessary minus included)");
while(!Serial.available()); // Wait for answer.
Time_change(Serial.read());
Serial.println("Succesfull");
return;
}
else
return;
}
}
void Mosfets::Output(int Do_step)
{
PORTB = Stap[Do_step];
delay(Time);
}
void Mosfets::Time_change(unsigned int Calculation)
{
Time += calculation;
}
uint8_t Mosfets::Mode_check(int Cur_mode)
{
if(Cur_mode==Mode)
return 1;
else
return 0;
}
Now when trying to compile i get an error about the fat part above.
The error is the following one : [b]Mosfets.cpp:90: error: explicit qualification in declaration of 'uint8_t Mode_check(int)'[/b]
I tried defining it as explicit, int Mode_check, byte Mode_check, but no luck
or int Mosfets::Mode_check(int Cur_mode)
{
if(Cur_mode== ::Mode)
return 1;
else
return 0;
}
neither work, was just testing what it could be, according to your reaction that type should only be used when defining var's ?
hey, thanks for the corrections , going to test right away, but why is the '_' in front of it ? and the '_h' does it mean header file or what is it for ?
Just so i understand the syntax and reasons behind it.
I read the tutorial again, and it says the _ is for marking private var's ?
Also, now I corrected the errors, i get an error on the var Stap not being declared in the scope on line 81, which is the Output() void, but i've declared it in the beginning of the cpp file , which i think is right, isn't it ? :s
Mosfets.cpp:81: error: 'Stap' was not declared in this scope
There's no compulsion to do it like that, but it makes it very unlikely that anyone else will ever define a macro starting with an underscore and ending with "_h".
Using plain vanilla "Mosfet" is not sensible, when you're going to define a class with exactly the same name.
Can you give me some more information on how to declare the var's so they can be used by the whole program?
Tought that was done by the 'public:' section, should i define them there, or can i do it in the '.cpp' file itself? All at the top ?
Because neither of them work, always getting the error 'Stap' (with the '_' in front of each var '_Stap' ==> declared in '.h', tried both) was not declared.
Or is it because i'm trying to acces a certain value of the array '_Stap' by this method : _Stap[Do_step]; ?
This works in Arduino tool, but don't know if i should do it different in the library.
I confused the fact that a private var can't be accessed by any other function from the outside, but if you define it within the class and not within a function that it can be used all over the class .
Sorry 'bout that.
Now i got the following :
#ifndef _Mosfets_h
#define _Mosfets_h
#include "Wprogram.h"
class Mosfets
{
private:
int _Stap[];
int _Time; //Initial time in ms the arduino will do
int _Mode; //Autorun mode
int _Manual_step;
int _Correct_Mode;
public:
void Init();
void Autorun();
void Manual();
void Change_mode(int data);
void Output(int Do_step);
void Time_change(unsigned int Calculation);
uint8_t Mode_check(int Cur_mode);
}
#endif
This is not all of the cpp file, but i'm getting an error on this void, namely Mosfets\Mosfets.cpp:6: error: two or more data types in declaration of 'Init'
So it's not allowed to define them there ? Why not ?
This _Stap[]= {B001101 , B110001 , B000111 , B010011 , B001101 , B011100}; is simply illegal in C or C++.
However, it's unclear to me if "Stap" is meant to be part of your class (in which case you'll either have to make it static, or initialise it explicitly in "init") or as you had it in your first post, and nothing really to do with your class.
Ok thanks.
If i declare it public, can i acces it from outside the .cpp ?
Like if i want to check in the arduino program what value '_Mode' has, can i acces it with Mosfets._Mode ? Or Mosfets::_Mode ?
Because now i got it going trough the init, which i had to rename to Mosfets::Mosfets to make it occur the first time the lib is called.
Or isn't this possible? Because i can compile now, the Mosfets::Mosfets is being called, but it seems i can't do
if(Mosfets._Mode==1){
Mosfets.Manual
}
while this would be a requirement to determine to which function i need to call .
:o