Java 中的 Arduino Map 等效函数
Arduino for Java中是否有类似于 Map 函数的函数?
我需要将一个范围的值映射到另一个范围的值,所以我想知道Java中是否有类似的东西,我一直在搜索,但我只得到Java的Map函数。
Is there a function similar to the Map function in Arduino for Java?
I need to map a range of values to another range of values, so I was wondering if there was something similar to it in Java, I've been searching but I only get the Java's Map function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Arduino 库中的
map()
代码如下:这在 Java 中同样有效 - 没有真正的魔法。但标准 Java 没有这样的预定义。
The code of
map()
from Arduino's library is this:This will work in Java just the same - no real magic. But standard Java has nothing predefined like this.
呃,Java 没有“Map”功能,它有一个 Map 类型,具有多种实现。但这只是一种存储机制,基本上会导致 key=>value 对。根据我对您链接的 Arduino 文档的阅读,您需要实现自己的方法来正确映射该值。
Uh, Java doesn't have a 'Map' function, it has a Map type in the Collections (java.util), with multiple implementations. But this is just a storage mechanism, basically resulting in key=>value pairs. Based on my reading of the Arduino docs you linked, you'd need to implement your own method to map the value appropriately.