Shop OBEX P1 Docs P2 Docs Learn Events
adc.scale(analog, 750, 2250) — Parallax Forums

adc.scale(analog, 750, 2250)

garylakegarylake Posts: 41
edited 2011-02-08 07:45 in Propeller 1
Trying figure out ADC. What does the 750, 2250 mean?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-07 17:49
    Which specific object would ADC be (the propeller tool version doesn't have a scale method)? It would also be nice if you could attach said object.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-02-07 17:56
    That looks like code from one of my demos. The purpose of the method is to take the value from the ADC and re-scale it to a new range; the second and third values specify the minimum and maximum values of the new range.
  • garylakegarylake Posts: 41
    edited 2011-02-07 18:21
    The said object is jm_adc0834_ez_demo.spin. And I do believe it is your demo, Jon.
    Ok, so if I want to rescale it to a range of midi velocity of 0-127 I would I would replace 750, 2250 with say 27, 127?
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-02-08 07:45
    For the ADC083x family, an 8-bit ADC, you don't need scale to go from 0-to-255 to 0-to-127, it's as simple as a 1-bit right shift:
    velocity = adc.read(V_CHAN) >> 1
    

    If you do in fact want your output scaled from 27 to 127, then the scale() method will do the trick -- and you can do it in one line of Spin:
    velocity = adc.scale(adc.read(V_CHAN), 27, 127)
    
Sign In or Register to comment.