How to adjust values to a new range


Results 1 to 27 of 27

Threaded View

  1. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    968


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: How to adjust values to a new range

    The concept of mapping a range should be clear by this code example in C explained

    // map a value(inputlow to inputhigh) to the range(outputlow to outputhigh)
    Code:
    int16   map(int16 val, int16 inpl, int16 inph, int16 outl, int16 outh){
    int32 tmp=MAX(val,inpl)-inpl;                         // tmp = (maximum of Val and inputlow) - inputlow
    
        tmp *= (outh-outl);                                      // tmp = tmp * (outputhigh - outputlow)
        tmp /= (inph-inpl);                                       // tmp = tmp / (inputhigh - inputlow)
        tmp += outl;                                                // tmp = tmp + outputlow
        return MIN(tmp,outh);                                 // return the lower of tmp or outputhigh
    }
    Last edited by Jerson; - 15th August 2024 at 03:10. Reason: formatting

Similar Threads

  1. Simple way to adjust interrupt speed in DT_INTS-14 ?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th January 2015, 12:01
  2. Use a pot to adjust COUNT value
    By Sam in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th November 2011, 15:56
  3. Select Case range of values
    By kenif in forum PBP Wish List
    Replies: 3
    Last Post: - 25th June 2009, 13:27
  4. Replies: 9
    Last Post: - 31st July 2008, 08:56
  5. If Then Range
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 29th June 2005, 14:33

Members who have read this thread : 5

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts