I have been trying to find the source code for the functions map() etc. I looked how to do it on the forum but I can't find the hardware or cores folder in my C drive. What should I do? I need this for a project.
Hello aarifh964
Take a view at github.
Did you install the IDE on your computer? If you are using the online version i don't know where it is. GitHub eould be the place to look.
Here is map():
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
On my PC for IDE version 1.8.19 the source code for that is in the IDE installation folder:
...\Arduino 1.8.19\hardware\arduino\avr\cores\arduino\WMath.cpp
What other functions are you looking for?
lots of the Arduino specific code is under Arduino/hardware/arduino/avr/cores/arduino
Arduino.h PluggableUSB.cpp USBDesc.h new.cpp
CDC.cpp PluggableUSB.h Udp.h new.h
Client.h Print.cpp WCharacter.h wiring.c
HardwareSerial.cpp Print.h WInterrupts.c wiring_analog.c
HardwareSerial.h Printable.h WMath.cpp wiring_digital.c
HardwareSerial0.cpp Server.h WString.cpp wiring_private.h
HardwareSerial1.cpp Stream.cpp WString.h wiring_pulse.S
HardwareSerial2.cpp Stream.h abi.cpp wiring_pulse.c
HardwareSerial3.cpp Tone.cpp binary.h wiring_shift.c
HardwareSerial_private.h USBAPI.h hooks.c
IPAddress.cpp USBCore.cpp main.cpp
IPAddress.h USBCore.h new
The answers provided so far are specific to the "Arduino AVR Boards" platform of the Uno, Mega, Leonardo, etc. boards. Even though the AVR-based boards are very popular, we must keep in mind that it is no longer 2010 and there is now a huge ecosystem of other boards, so it is not a safe assumption to make.
If you are compiling for a different board, then the function will be in a different location.
I'll share a technique that will work for any board:
- Select File > Preferences from the Arduino IDE menus.
- Check the box next to "Show verbose output during: ☐ compilation".
- Click the OK button.
- Select File > New from the Arduino IDE menus.
ⓘ It doesn't matter which sketch you compile. We only need to get the verbose compilation output. - Select the board you want to find the function for from Arduino IDE's Tools > Board menu.
- Select Sketch > Verify/Compile from the Arduino IDE menus.
- Wait for the compilation to finish.
- Examine the contents of the black output panel at the bottom of the Arduino IDE window. If you scroll up, you will see a line that looks something like this:
Using core 'arduino' from platform in folder: /home/per/.arduino15/packages/arduino/hardware/samd/1.8.13
The files containing the definitions of the Arduino core API functions for the selected board are found under the cores
folder at the path shown in that line. In my example, the full path to the file containing this specific function is:
/home/per/.arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Common.cpp
If you are using Arduino IDE 2.x, there is an even better way to see the source of any function:
- Select the board you want to find the function for from Arduino IDE's Tools > Board menu.
- Right click on the function you want to find the source of.
- Select "Go to Definition" from the context menu.
The file containing the function's definition will open in a tab in Arduino IDE.
RTFM is so true, especially for this function:
https://www.arduino.cc/reference/en/language/functions/math/map/
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.