Go Down

Topic: Classes (Read 2 times) previous topic - next topic

AWOL

#15
Jun 13, 2010, 08:32 pm Last Edit: Jun 13, 2010, 08:36 pm by AWOL Reason: 1
Code: [Select]
confirmation = Serial.available();
     Serial.flush();
     if(confirmation == "Y")

Oops.
(make that two "oops")

Code: [Select]
Correct_mode = mode_check(1);
"mode_check" is void, so you can't assign the value that it doesn't return to anything.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BloodyD

#16
Jun 13, 2010, 08:37 pm Last Edit: Jun 13, 2010, 08:38 pm by Bloodyd Reason: 1
Why ? :s
it saves the serial data to the var, and then clears the serial data if any there , or am i wrong ? :s

And the void , i tell it to return something, a 1 or a 0, that is something, or what do you mean?

AWOL

"available" returns how many characters are in the rx buffer, not the vaues of the characters.

Code: [Select]
== "Y" is very unlikely to work.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BloodyD

#18
Jun 13, 2010, 08:39 pm Last Edit: Jun 13, 2010, 08:41 pm by Bloodyd Reason: 1
Ow .. another failure today -.-
thanks for getting that 1 out :-)
had it on 1/2 other places to , fixed those.

Updating Code on previous page.

AWOL

#19
Jun 13, 2010, 08:43 pm Last Edit: Jun 13, 2010, 08:44 pm by AWOL Reason: 1
Code: [Select]
void Mode_check(int Cur_mode)
 {
     if(Cur_mode==Mode)
       return "1";
     else
       return "0";
 }


void?
string pointers?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BloodyD

Aren't that just values ?
Like int val = 1; , but then just returning the value straight away ?

AWOL

#21
Jun 13, 2010, 08:55 pm Last Edit: Jun 13, 2010, 09:07 pm by AWOL Reason: 1
It's a "void" - it doesn't return anything, much less a const char pointer.

[edit]
Code: [Select]
if(temp_save = 1)
       Mode = 0;
       else
       Mode = 1;

That "=" is probably a problem.
Why not just "Mode = 1 - temp_save;" ?
[/edit]

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BloodyD

Thats right , should be a '==' , but why would i do that ? mode 0 is the 'autorun' mode, 1 is the 'manual' mode, so if temp_save would be on 1 (meaning manual) it would return to automatic.
Unless i turn these values around ofc.

So that void part, would mean i have to turn it into a function to get what i want ?

BloodyD

#23
Jun 13, 2010, 09:45 pm Last Edit: Jun 13, 2010, 09:47 pm by Bloodyd Reason: 1
yeah it's a function, but i mean to get the 'return' part working , i should make it
Code: [Select]

 int Mode_check(int Cur_mode)
 {
     if(Cur_mode==Mode)
       return "1";
     else
       return "0";
 }    

like this then ?
and oh yeah, i see know, sorry :-)
I didn't tought 'bout it that way, think i should use
Code: [Select]
Mode = 0+temp_save; then instead tough, seems i've made another mistake against my own interpretation.
temp_save should be 1 to change to manual mode, then Mode must be 1 to make it apply in the whole program.

And a void can't return a value, but I can use the return statement to exit the void, right ?
Thanks.

AWOL

Quote
int Mode_check(int Cur_mode)

Yes, except a const char pointer isn't an "int".

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BloodyD

ok, so i should leave away the quotes . i've removed some of the minor faults, like forgetting ';' and some other '=', ' " ' , conversion faults, and now at least it compiles.

Great, thanks for helping me so far :-) Shall i post the program again ? So if you have some more suggestions on how to improve you can give them from the program i'm currently using.

Code: [Select]

int Stap[6] =  
   {
     B001101 , B110001 , B000111 , B010011 , B001101 , B011100};
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.

class Arduino
{
 public:
   void port()
   {
     Serial.begin(9600);
     DDRB = B111111;
   }
   
   void Autorun()
   {
     for(int i=0;i <=5;i++)
     {
       Correct_mode = Mode_check(0);
       if(Correct_mode == 1)
       Output(i);
     }      
   }
   
   void Output(int do_step)
   {
     PORTB = Stap[do_step];
     delay(Time);
   }
   
   void Manual()
   {
     Correct_mode = Mode_check(1);
     if(Correct_mode == 1)
       Output(Manual_step);
   }
   
   void Time_change(int minus)
   {
     Time -= minus;
   }
   
   void Mode_change(int mode)
   {
     int temp_save = mode;
     char confirmation;
     
     Serial.println("Do you want to modify the step?(1/0");
     Serial.flush();
     do
     {
       delay(1);
     }
     while(!Serial.available());
     confirmation = Serial.read();
     Serial.flush();
     if(confirmation == 1)
     {
       Mode = 0+temp_save;
       Serial.println("What step do you want to program?");
       do
       {
         delay(1);
       }
       while(!Serial.available());
       Manual_step = Serial.read();
       Serial.flush();
       Serial.println("Succesfull");
     }
     
     else if(confirmation == 0)
     {  
       Serial.println("Do you want to adjust the time/cycle? (1/0)");    
       do
       {
         delay(1);
       }
       while(!Serial.available());
       confirmation = Serial.read();
       if(confirmation == 1 )
       {
         Serial.println("With how much do you want to subtract?");
         do
         {
           delay(1);
         }
         while(!Serial.available());
         Time_change(Serial.read());
         Serial.println("Succesfull");
         return;
       }
     }
   }

     
 int Mode_check(int Cur_mode)
 {
     if(Cur_mode==Mode)
       return 1;
     else
       return 0;
 }    
};
void setup()
{
 Arduino config;
 config.port();
}

void loop()
{
 Arduino Program;
 if(Serial.available()>0)
 Program.Mode_change(Serial.read());
 if(Mode==0)
 Program.Autorun();
 if(Mode==1)
 Program.Manual();
 
}


;D

AWOL

Code: [Select]
do
       {
         delay(1);
       }
       while(!Serial.available());


I'm unclear why you've got a "delay" in there,

Code: [Select]
while (!Serial.available ()) ;
would do the same job, and prove more responsive at baud rates higher than 9600,
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BloodyD

I can't recall why i used the delay, probably to make something that would print a message after f.e. A few minutes that it's still waiting for answer or something.
But you're right, i should do it with timers and then make the interrupt instead of using that delay.
Altough i have to figure out how to config the timers and use them by registers then.
Can you tell me how i should capture an interrupt given by timer1?

Go Up