PureBasic Forum

 It is currently Sat Jan 23, 2021 12:56 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Arduino’s map() FunctionPosted: Fri Apr 10, 2020 6:46 pm
 Enthusiast

Joined: Sun Jul 07, 2013 11:35 am
Posts: 587
Hello everyone,

While I'm working on Steering behaviors "Arrival" I have found a video explaining it (See https://www.youtube.com/watch?v=2CL1maXeQCI). It use a Map() function to calculate the speed reduction in relation to the distance to the target point. After some research I have found an implementation that I have converted into a Macro for PB.

Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : MappingValues
; File Name : MappingValues.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 10-04-2020
; Last Update : 10-04-2020
; PureBasic code : V5.72
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Programming notes
;
; Based on a code found here :
;
; https://www.jetmore.org/john/blog/2011/09/arduinos-map-function-and-numeric-distribution/
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Macro MappingValues(x, in_min, in_max, out_min, out_max)

((x - (in_min)) * ((out_max) - (out_min)) / ((in_max) - (in_min)) + (out_min))

EndMacro

CompilerIf #PB_Compiler_IsMainFile

For Index = 0 To 100
Debug StrF(MappingValues(Index, 0.0, 100.0, 0.0, 15.0), 4)
Next

CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<

Best regards
StarBootics

_________________
The Stone Age did not end due to a shortage of stones !

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC + 1 hour

Who is online

Users browsing this forum: mk-soft and 27 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite