module Aio::Helpers
This module adds most of the Arduino Reference functionality.
Check the {www.arduino.cc/en/reference/homePage Arduino Reference} for more information about them.
Public Instance Methods
abs(num)
click to toggle source
# File lib/aio/helpers.rb, line 44 def abs(num) num > 0 ? num : -num end
bit(n)
click to toggle source
# File lib/aio/helpers.rb, line 16 def bit(n) 2**n end
bitClear(num, pos)
click to toggle source
# File lib/aio/helpers.rb, line 20 def bitClear(num, pos) num & ~(0x01 << pos) end
bitRead(num, pos)
click to toggle source
# File lib/aio/helpers.rb, line 28 def bitRead(num, pos) (num & (0x01 << pos)) >> pos end
bitSet(num, pos)
click to toggle source
# File lib/aio/helpers.rb, line 24 def bitSet(num, pos) num | (0x01 << pos) end
bitWrite(num, pos, value)
click to toggle source
# File lib/aio/helpers.rb, line 32 def bitWrite(num, pos, value) value == 0 ? bitClear(num, pos) : bitSet(num, pos) end
constrain(value, a, b)
click to toggle source
# File lib/aio/helpers.rb, line 72 def constrain(value, a, b) return a if value < a return b if value > b value end
cos(rad)
click to toggle source
# File lib/aio/helpers.rb, line 60 def cos(rad) Math.cos(rad) end
highByte(num)
click to toggle source
# File lib/aio/helpers.rb, line 12 def highByte(num) num & 0xff00 end
lowByte(num)
click to toggle source
# File lib/aio/helpers.rb, line 8 def lowByte(num) num & 0xff end
map(value, min0, max0, min1, max1)
click to toggle source
# File lib/aio/helpers.rb, line 68 def map(value, min0, max0, min1, max1) ((value - min0) * (max1 - min1) / (max0 - min0)) + min0 end
max(x, y)
click to toggle source
# File lib/aio/helpers.rb, line 40 def max(x, y) x < y ? y : x end
min(x, y)
click to toggle source
# File lib/aio/helpers.rb, line 36 def min(x, y) x < y ? x : y end
pow(base, exponent)
click to toggle source
# File lib/aio/helpers.rb, line 48 def pow(base, exponent) base ** exponent end
random(a, b = nil)
click to toggle source
# File lib/aio/helpers.rb, line 78 def random(a, b = nil) (a and b) ? rand(a..b) : rand(a) end
randomSeed(seed)
click to toggle source
# File lib/aio/helpers.rb, line 82 def randomSeed(seed) srand(seed) end
sin(rad)
click to toggle source
# File lib/aio/helpers.rb, line 56 def sin(rad) Math.sin(rad) end
sqrt(num)
click to toggle source
# File lib/aio/helpers.rb, line 52 def sqrt(num) Math.sqrt(num) end
tan(rad)
click to toggle source
# File lib/aio/helpers.rb, line 64 def tan(rad) Math.tan(rad) end