arduino-copilot-1.5.5: Arduino programming in haskell using the Copilot stream DSL
Safe HaskellNone
LanguageHaskell2010

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

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

Instances details
Output RandomSeed (Event () (Stream Word8)) Source # 
Instance details

Defined in Copilot.Arduino.Library.Random

Methods

(=:) :: RandomSeed -> Event () (Stream Word8) -> Sketch () Source #

Output RandomSeed (Event () (Stream ADC)) Source # 
Instance details

Defined in Copilot.Arduino.Library.Random

Methods

(=:) :: RandomSeed -> Event () (Stream ADC) -> Sketch () Source #

data RandomInput Source #

Instances

Instances details
Input RandomInput Word32 Source # 
Instance details

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)

randomR :: (Word32, Word32) -> RandomInput Source #

Generate a random number in the range (lo, hi). The number will be >= lo and < hi

n <- input (randomR 5 10) :: Sketch (Behavior Word32)