how to get integers from analogRead

Posted on
  • I'm reading chunks of data using Waveform, which returns UInt values.
    There are accompanying single measurements via analogRead. Unfortunately analogRead values need to be converted from Float to Integer to be comparable with the Waveform data. Is there a way to make analogRead return integers (may be a flag)?
    Any other reliable, though probably hacky way to get ADC data fast and as int?

  • Just multiply the analogRead value by 65536 (assuming you're reading a 16 bit waveform?) - that's all you should need.

  • Well, of course. In the code there is a function jshPinAnalogFast - can I acces it from JS?

  • ... or can and want you enhance analogRead to take an optional 2nd parameter (boolean, true) to return the integer?

  • You can't access it from JS - I don't understand why you'd want to? It produces a lower quality output most of the time - but when you're calling it from JS the speed really doesn't matter - it's a very small percentage of the overall JS execution time

  • Having seen that in the C code for analogRead, as one of the last steps the data is divided by 65536, I thought why not shortcut it.
    I'm really fine with multiplying again in my special case.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

how to get integers from analogRead

Posted by Avatar for Steffen @Steffen

Actions