Thread: How to create On/OFF button wth C programming?

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    4

    How to create On/OFF button wth C programming?

    O – On / Off button
    By default the button is in Off state. When, in this state, and the O button is selected, the machine is in On state. When in On state, and the O button is selected, it is changed to the Off state and all entries prior to this are reset to original state.

    Main Menu
    Once the machine is turned On (using the On / Off button) the user will have the option of deciding whether to Wash Clothes (W) or View Log (V).
    Wash Clothes
    Once this option is selected, the Load Capacity Menu appears.
    View Log
    When this option is selected, the user would be able to view the washing machine operation logs according to the dates.

    Load Capacity Menu
    Here the user will need to select the size of the load from the Load Capacity Menu, which could include any one of the following options:
    S – Small
    M – Medium
    L – Large
    X – Extra Large
    F – Free Load
    If the user is not sure on which size to select (s)he has the option to choose F (Free Load). This means that the user would depend on the machine to determine the Load Capacity based on the weight of the clothes. The weight of the clothes can be a random generated value but its value has to be a logical weight for clothes put into a washing machine. When the weight is determined then the Load Capacity is set automatically to Small, Medium, Large or Extra Large. Note that there should be a minimum and maximum value for each Load Capacity type. E.g. Small should between 1 – 2 kg, etc.

    Wash Menu
    When the size of the load has been determined, the Wash Menu is activated. The user now gets to select from one of the following Wash Menu options:
    F – Full Wash
    W – Wash
    R – Rinse
    S – Spin

    Full Wash
    A Full Wash would consist of Washing, Rinsing and Spinning but may include Soak depending on the selection made in the Soak Menu which appears when the Full Wash is activated. In the Soak Menu the user has the option to select from the following:
    N – No soaking
    S – Soak
    When the user selects N, the program will proceed to the next menu option – Temperature Menu. If the selects S, the system will prompt the user for the number of minutes to soak. The user can key in any value between 1 – 60 minutes. After the number of minutes is determined the program will proceed to the next menu option – Temperature Menu.

    Wash
    The Wash would consist of only Washing – without rinsing or spinning. However, it may include Soak depending on the selection made by the user from the Soak Menu which appears when the Wash is activated. The description of the Soak Menu is as listed above.

    Rinse
    The Rinse would consist of only Rinsing – without washing, spinning or soaking. The user would not have the option of selecting the temperature as well.

    Spin
    The Spin would consist of only spinning – without washing, rinsing or soaking. The user would not have the option of selecting the temperature as well.

    Temperature Menu
    This menu is activated only after either the Full Wash or the Wash option has been selected. The Temperature Menu contains the following option:
    H – Hot
    C – Cold
    If the user selects H, hot water will be used for all operations – from soaking to rinsing.
    Or else cold water will be used.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    How to.......... On/Off.......?
    Code:
    enum button{on,off}your_button;
    The rest is up to you.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    This sounds suspiciously like homework...

    Homework Policy <-- yes that's a link... click on it.

    Show some initiative ... get started on this yourself.

    1) Analyse the problem you have, think about it until you understand what is required of your code...
    2) Once you know what the problem is, write a plan --yes with pencil and paper-- that solves the problem
    3) Write code that enacts your plan...
    4) Test your code...

    If you get stuck --really stuck, not lazy stuck-- post your code and we'll see what we can do.

    We do not write code for you...

  4. #4
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Quote Originally Posted by manasij7479 View Post
    Code:
    enum button{on,off}your_button;
    The rest is up to you.
    thanks, I need just to know how to make on/off that's all, I'll try.

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Quote Originally Posted by CommonTater View Post
    This sounds suspiciously like homework...

    Homework Policy <-- yes that's a link... click on it.

    Show some initiative ... get started on this yourself.

    1) Analyse the problem you have, think about it until you understand what is required of your code...
    2) Once you know what the problem is, write a plan --yes with pencil and paper-- that solves the problem
    3) Write code that enacts your plan...
    4) Test your code...

    If you get stuck --really stuck, not lazy stuck-- post your code and we'll see what we can do.

    We do not write code for you...
    No no you guys got me wrong, actually the question is about ON/Off, the rest I'll try by myself. This coding i have beed taught at Univercity, first level, I have just written the others to be perceptively to you.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    We still don't hand out code...

    Make the attempt on your own, post the problem code...

    I will give you one hint... You will need an equals sign, a question mark and a colon.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    This is a program for which a state machine type of design makes sense.

    Finite-state machine - Wikipedia, the free encyclopedia

    Tim S.

  8. #8
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    How to you use enum button on/off. I am so freaking dummy in this programming.

  9. #9
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Example:
    Code:
    #include <stdio.h>
    
    int main(void){
    
    	enum{off, on}button;
    
    	button = on;
    
    	if(button)
    	     printf("button on, value is %d\n", button);
    
    	button = off;
    	if(!button)
    	     printf("button off, value is %d\n", button);
    
    	getchar();
    	return (0);
    }
    Last edited by AndrewHunter; 08-11-2011 at 10:56 PM.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Aziz Khakim View Post
    How to you use enum button on/off. I am so freaking dummy in this programming.
    Oh for crying out loud...
    Code:
    int IsOn = 0;  // initialize to off
    
    // a loop to demonstrate
    for (int x = 0; x < 10; x++)
      {
         // toggle on and off
         IsOn = IsOn ? 0 : 1;
    
         If (IsOn) 
           printf("It's turned on!");
        else 
          printf("It's not turned on");
    
         }
    Ok... get it now?

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    35
    I dont mean to sound trite, but arent buttons something for object oriented programming C++ and not top/down programming?
    Last edited by Linux Trojan; 08-12-2011 at 12:16 PM. Reason: typo

  12. #12
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Linux Trojan View Post
    I dont mean to sound trite, but arent buttons something for object oriented programming C++ and not top/down programming?
    How so? What exactly do you mean by button in your context?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  13. #13
    Registered User
    Join Date
    Jun 2011
    Posts
    35
    It sounds like he wants to do a lot of independent activities. My understanding is that object oriented is more appropriate because you can run different parts of the program independently without having to start at the top of the program and flow through sequentially. I do programming in Gambas and Visual Basic so button to me means a special section of the program. Maybe, I dont quite understand the problem, dunno.

  14. #14
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Umm.....The C compiler goes through source code in a top down method but the actual program itself is executed according to the logical flow made by the programmer. I guess I don't understand what you mean by this:

    Quote Originally Posted by Linux Trojan View Post
    My understanding is that object oriented is more appropriate because you can run different parts of the program independently without having to start at the top of the program and flow through sequentially.
    Program flow doesn't really have anything to do with OOP.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Linux Trojan View Post
    It sounds like he wants to do a lot of independent activities. My understanding is that object oriented is more appropriate because you can run different parts of the program independently without having to start at the top of the program and flow through sequentially. I do programming in Gambas and Visual Basic so button to me means a special section of the program. Maybe, I dont quite understand the problem, dunno.
    Yoo Hoo... he's in a programming course learning C.

    He wants to push a keyboard button to toggle his "machine" on and off...
    I gave a perfectly simple and easy example of how to toggle a value... the rest is up to him.
    Last edited by CommonTater; 08-12-2011 at 01:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to create PWM signal using c programming
    By pearl87 in forum C Programming
    Replies: 8
    Last Post: 08-23-2010, 06:34 AM
  2. create sound in C++ programming...how???
    By SweeLeen in forum C++ Programming
    Replies: 10
    Last Post: 09-25-2005, 10:24 AM
  3. create C dll for other programming languages
    By corn in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2003, 01:11 AM
  4. Create event for run-time button?
    By Robert in forum C++ Programming
    Replies: 11
    Last Post: 03-30-2002, 07:56 PM