Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Copilot.Arduino.Library.Random
Description
Random value library for arduino-copilot.
Here's an example that flashes the LED randomly.
main :: IO () main = arduino $ do if firstIteration then randomSeedPin a0 else do n <- input (random 10) :: Sketch (Behavior Word32) led =: (n >= 5)
The use of firstIteration
makes the RNG be seeded in the first
iteration, and then random numbers are generated in subsequent
iterations. That's a typical pattern when using this module.
Synopsis
- randomSeed :: RandomSeed
- randomSeedPin :: IsAnalogInputPin t => Pin t -> Sketch ()
- data RandomSeed
- data RandomInput
- random :: Word32 -> RandomInput
- randomR :: (Word32, Word32) -> RandomInput
Documentation
randomSeed :: RandomSeed Source #
Use this to seed the RNG.
randomSeed =: constant (1 :: Word8)
randomSeedPin :: IsAnalogInputPin t => Pin t -> Sketch () Source #
Seed the RNG by reading from an analog input pin.
If the pin is left unconnected, noise will be read from it.
data RandomSeed Source #
Instances
Output Arduino RandomSeed (Event () (Stream ADC)) Source # | |
Defined in Copilot.Arduino.Library.Random | |
Output Arduino RandomSeed (Event () (Stream Word8)) Source # | |
Defined in Copilot.Arduino.Library.Random |
data RandomInput Source #
Instances
Input Arduino RandomInput Word32 Source # | |
Defined in Copilot.Arduino.Library.Random |
random :: Word32 -> RandomInput Source #
Generate a random number, up to but exclusive of an upper bound.
n <- input (random 10)