• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Map() funcation in micropython

Q&A Forum › Category: ESP32 › Map() funcation in micropython
0 Vote Up Vote Down
wael elsisi asked 4 years ago

I’m newbie in micropython
How to write map function as in Arduino?
mappedValue = map(moistureValue,AirValue,WaterValue, 0, 100);
All what I can do in micropython as following:
from machine import Pin, ADC
from time import sleep
moistureValue= ADC(Pin(A0))
moistureValue.atten(ADC.ATTN_11DB)

 

2 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
There isn’t such function in MicroPython. But you can define your own function to do that.
Declare the function:

def scale_value(value, in_min, in_max, out_min, out_max):
  scaled_value = (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
  return scaled_value

Then, just call the function with the desired parameters and it will return the mapped value.
I hope this helps.
Regards,
Sara
 

0 Vote Up Vote Down
wael elsisi answered 4 years ago

Thank you .

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.