Go Down

Topic: Arduino instead of a washing machine timer (Read 1 time) previous topic - next topic

kennethagiusmosta

Hi all,

I would like to use Arduino instead of a washing machine timer. Basicly the idea is to use 11 relays as outputs to control the motor, 2 water pumps, heater and the dock lock. 4 washing programs will be available and a terminate button to end program thus empting the machine and unlock the door (if necessary).

I'be try this with leds, experiminting with some progamming, before spending the necessary relays, transistors.. ect

Since I'm new to Arduino, any comments are appricated. Some questions thou;

Is Arduino memory enough for perform a complex program?
Are there any Goto or Gosub (s) line comands so to avoid repeated commands?

Thanks in advance
Kenneth Agius from MALTA.


Oracle

It's actually a fairly simple program and the arduino is more than capable.  

The challenges will be the mechanical setup, hooking up the relays, etc.

There are program structures such as for loops and if statements to handle the program flow, a goto is generally considered to be bad programming, is basically never used in a high level language.

Gosub is not used in high level languages, you will use functions.

westfw

Make sure you understand the "safety" interlocks built into existing timer before your reproduce it on your arduino.  It would be a shame to miss reading that overflow sensor and end up with water all over...


westfw

#3
Apr 15, 2008, 10:39 am Last Edit: Apr 15, 2008, 10:47 am by westfw Reason: 1
Quote
Gosub is not used in high level languages, you will use functions.

"Gosub" is a BASIC construct for calling subroutines.   Arduino has subroutines (aka "functions") that work about the same, but are defined and called differently.

Here's some code from the Basic Stamp Reference Manual:
Code: [Select]
Main:
 DEBUG CLS                             ' Clear DEBUG window
 FOR phrase = 1 TO 6                   ' Print blocks one by one
   LOOKUP (phrase - 1),
          [Text1, Text2, Text3, Text4, Text5, Text6], idx
   GOSUB Print_It
   PAUSE 5000                          ' Pause for 5 seconds
 NEXT
 END

Print_It:
 DO
   READ idx, char                      ' Get next character
   idx = idx + 1                       ' Point to next location
   IF (char = 0) THEN EXIT             ' If 0, we're done with block
   DEBUG char                          ' Otherwise, transmit it
 LOOP
 RETURN                                ' Return to the main routine

Similar code in C (for arduino) would look something like this:
Code: [Select]

void print_it(int idx)
{
  char c;
  do {
    c = readdata[idx];
    idx += 1;
    if (c == 0) {
       break;
    }
    debug(c);
 } while (1);
}

main(void)
{
  int phrase, idx;
  debug(CLS);
  for (phrase = 0; phrase < 6; phrase++) {
    idx = lookup(phrase, textarray);
    print_it(idx);
    delay(5000);
  }
}

kennethagiusmosta

Thanks

I still can't understand "gosub" in C.
It seems like VB or VBA thus a function which returns a value. Can it be used several times? What I mean is why writing the same commands when you can call a routine 1,2,3 or many times you want.


kennethagiusmosta


Main:
 DEBUG CLS
'do something

gosub TURN_IT
'do something else

gosub TURN_IT
'do something else
                       
END


TURN_IT:

'turn motor left for 5 sec
'turn motor right for 5 sec

RETURN      

spiffed

Your code would look something like this:

Code: [Select]

void turn_it(){
 turn motor left for 5 sec;
 turn motor right for 5 sec;
}

void setup(){
   //if you needed to set something up when you power the device on, do it here.
}

void loop(){
  //the Arduino runs this code in a loop, forever.

 do_something;
 do_something_more;

 turn_it();

 do_something_else;
 do_something_else_more;

  turn_it();

  do_something_else;
  do_something_else_more;

  turn_it();
}

iDuino - MaxSerial - [url=http://spi

kennethagiusmosta


Oracle

Quote
Quote
Gosub is not used in high level languages, you will use functions.

"Gosub" is a BASIC construct for calling subroutines.   Arduino has subroutines (aka "functions") that work about the same, but are defined and called differently.


Gosub works very similary to assembly level of CALL and RETURN, so even though the word is a BASIC construct, I had to choose my wording very carefully.

And I'm also very reluctant to say never use a goto because there are cases where it's the right thing to do, even in a HLL, but for an average user, it is best to tell them to never use one.

Anyway, I'm sure you know all this far better than I do.  See you on the piclist ;)

westfw

Quote
I still can't understand "gosub" in C.
It seems like VB or VBA thus a function which returns a value.

Yes.  C does not have a signficant difference between functions (subroutines that return a value) and procedures (subroutines that do not return a value.)  This makes it somewhat different than BASIC, ForTran, and some other languages.  In C, you just define a "function" that returns "void" (ie nothing.)

Go Up