How to adjust values to a new range


Results 1 to 27 of 27

Threaded View

  1. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: How to adjust values to a new range

    Quote Originally Posted by Ioannis View Post
    Since you have done it in PBP and if you don't mind, could you post the code you tested please? ....

    Sure thing:

    Code:
    ADCinput    var WORD
    ADCcalc     var WORD
    ADCinLow    con 0
    ADCinHigh   con 255
    ADCoutLow   con 100
    ADCoutHigh  con 235
            ADCcalc = ADCinput / 4          ' reduce to 0-255 to avoid WORD overflow
            ADCcalc = (ADCcalc MAX ADCinlow) - adcinlow ' adjust 0 - 255 range
            ADCcalc = ADCcalc * (ADCouthigh - adcoutlow)'   to 100 - 235 range
            ADCcalc = ADCcalc / (adcinhigh - adcinlow)
            ADCcalc = ADCcalc + ADCoutlow
            ADCcontrast = ADCcalc MIN ADCouthigh
    I just kept things simple and did things one step at a time, just like Jerson explained it. And women say men can't follow instructions.

    I know I can shrink this, but I'm just researching all the different bits of code I will need first, and documenting with comments what the code does and why.
    Last edited by Demon; - 15th August 2024 at 19:23.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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

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