Pages: 1 [2]   Go Down
Author Topic: Classes  (Read 2189 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 287
Posts: 25682
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
confirmation = Serial.available();
      Serial.flush();
      if(confirmation == "Y")
Oops.
(make that two "oops")

Code:
Correct_mode = mode_check(1);
"mode_check" is void, so you can't assign the value that it doesn't return to anything.
« Last Edit: June 13, 2010, 01:36:58 pm by AWOL » Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: June 13, 2010, 01:38:36 pm by Bloodyd » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 287
Posts: 25682
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
== "Y"
is very unlikely to work.
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 13, 2010, 01:41:04 pm by Bloodyd » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 287
Posts: 25682
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

void?
string pointers?
« Last Edit: June 13, 2010, 01:44:05 pm by AWOL » Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 287
Posts: 25682
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a "void" - it doesn't return anything, much less a const char pointer.

[edit]
Code:
if(temp_save = 1)
        Mode = 0;
        else
        Mode = 1;
That "=" is probably a problem.
Why not just "Mode = 1 - temp_save;" ?
[/edit]

« Last Edit: June 13, 2010, 02:07:10 pm by AWOL » Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah it's a function, but i mean to get the 'return' part working , i should make it
Code:
 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:
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.
« Last Edit: June 13, 2010, 02:47:19 pm by Bloodyd » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 287
Posts: 25682
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
int Mode_check(int Cur_mode)
Yes, except a const char pointer isn't an "int".

Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 287
Posts: 25682
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Code:
while (!Serial.available ()) ;
would do the same job, and prove more responsive at baud rates higher than 9600,
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: 1 [2]   Go Up
Jump to: