Thread: almost there.... please help

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    7

    almost there.... please help

    How do I incorporate an if/then into this to print a warning messege when a specified value is reached on the potentiometer.

    int ReadPot()
    {

    int i;

    pin = output; pin = l;
    for (i = 0; i < charge; i++);
    pin = input;
    for ( i = 0; pin == l; i++);

    return I ;

    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You should be waterboarded for not properly using code tags.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by TommyBoy View Post
    How do I incorporate an if/then into this to print a warning messege when a specified value is reached on the potentiometer.

    Code:
    int ReadPot()
    {
    
    int i;
    	
    	pin = output; pin = l;
    	for (i = 0; i < charge; i++);
    	pin = input;
    	for ( i = 0; pin == l; i++);
    
    	return I ;
    
    }
    Sorry, that won't compile. You have declared i, but not I, and you have set pin equal to 'l', having never declared it as a variable.

    Please post up the code that you're actually using - we can't give you good advice with this example.

    Code:
    if(vcPot == warningValue)
      ( print your warning message here);
    That's pretty lousy, but it's the best I can do with your example code.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    7

    latest progress

    does this look any better?


    function ReadPot()
    {
    int i;
    i = output;
    for(i;i<=charge;i++){

    if(i>=1290){
    printf("WARNING: MAX VALUE EXCEEDED\n");
    return 0;
    }
    }
    return 0;
    }

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by MacGyver View Post
    You should be waterboarded for not properly using code tags.
    Perhaps you think this is an idle threat.

    << !! Posting Code? Read this First !! >>

    You can combine
    Code:
    int i;
    i = output;
    into "int i = output;". Where is "charge" defined/declared?

    ps. next time hold your breath
    Last edited by MK27; 06-11-2009 at 11:57 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Code:
    function ReadPot() {
      int i;
      i = output;
      for(i;i<=charge;i++){
    
        if(i>=1290){
          printf("WARNING: MAX VALUE EXCEEDED\n");
          return 0;
        }
      }
      return 0;
    }
    Yes, that does look better - but without knowing all the details of the rest of your code or what problem you're trying to solve - we can't say much more than that. Does it work for you?

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    7
    Code tag box wasn't there, thanks for your concern Ace.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TommyBoy View Post
    Code tag box wasn't there, thanks for your concern Ace.
    Hey Mr. Attentive! I did edit my post to include some useful info, I think. I didn't expect you to be so fast.

    Isn't the potentiometer the main ingredient of the WAH_WAH pedal?

    ps. you are suppose to add the code tag box dufus. It's not hard. Get used to it.
    Last edited by MK27; 06-11-2009 at 12:02 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Jun 2009
    Posts
    7
    Thanks for your help MK...

  10. #10
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    You might wanna return something other than 0 when max value is exceeded to differentiate a normal return from an abnormal one.

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Code:
      int i;
      i = output;
      for(i;i<=charge;i++){
    Following up on what MK27 said, you can actually combine this all into one line:

    Code:
    for(int i=output;i<charge;i++) {

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by sean
    Code:
    for(int i=output;i<charge;i++) {
    That is contra C99.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Oh riiight... yes - my bad.

Popular pages Recent additions subscribe to a feed

Tags for this Thread