0Pricing
Arduino & IoT Academy · درس

تعيين قيم map() إلى نطاق جديد

إعادة تحجيم القراءات الخام إلى وحدات مفيدة

تعيين قيم map() إلى نطاق جديد درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Raw Values Are Awkward

A 0 to 1023 reading rarely matches what you need. Often you want a percentage or an angle, not a raw sensor count.

Meet the map Function

The map function rescales a number from one range into another. It does the proportional math so you do not have to.

Its Five Arguments

You give map five things: the value, plus the low and high of its current range and the low and high of the target range.

map(value, fromLow, fromHigh, toLow, toHigh);

Scale to a Percentage

To turn a knob into 0 to 100 percent, map from the analog range to a percent range. The result reads like a volume dial.

int pct = map(analogRead(A0), 0, 1023, 0, 100);

Scale to a Servo Angle

Servos expect 0 to 180. Map a knob into that range and the reading becomes a usable angle for the motor.

int angle = map(analogRead(A0), 0, 1023, 0, 180);

It Returns Whole Numbers

The map function works in integers, so it returns whole numbers and drops the fraction. That is fine for most controls.

You Can Flip the Range

Set the target low above the high to invert the output. Now turning the knob right makes the result go down.

int v = map(analogRead(A0), 0, 1023, 100, 0);

It Does Not Clamp

The map function will go past your limits if the input does. Use constrain afterward to keep the result safely inside bounds.

int v = constrain(map(x,0,1023,0,100),0,100);

Negative Ranges Work Too

Targets can be negative, like -50 to 50 for a centered control. The map math handles that direction with no extra effort.

Map for Brightness

Pair map with PWM later to set brightness. A knob can scale neatly into the 0 to 255 range an LED dimmer expects.

int b = map(analogRead(A0), 0, 1023, 0, 255);

A Tool You Will Reuse

You will reach for map constantly: percentages, angles, ranges, and more. It turns raw sensor data into meaningful numbers.

Quick Check

What is the job of the map function?

Recap: Rescaling with map

You learned map rescales a value between ranges using five arguments. Pair it with constrain to clamp results into safe bounds.

الأسئلة الشائعة

هل درس «تعيين قيم map() إلى نطاق جديد» مجاني؟

نعم — نص درس «تعيين قيم map() إلى نطاق جديد» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

ماذا ستتعلم في «تعيين قيم map() إلى نطاق جديد»؟

إعادة تحجيم القراءات الخام إلى وحدات مفيدة تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟

لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تعيين قيم map() إلى نطاق جديد»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟

نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الإشارات الرقمية مقابل التناظرية
  2. إرجاع analogRead للقيم 0–1023
  3. قراءة مقبض مقياس الجهد
  4. تعيين قيم map() إلى نطاق جديد
← العودة إلى Arduino & IoT Academy