module System.Hardware.Arduino.SamplePrograms.Analog where
import Control.Monad (when)
import Control.Monad.Trans (liftIO)
import System.Hardware.Arduino
analogVal :: IO ()
analogVal :: IO ()
analogVal = Bool -> FilePath -> Arduino () -> IO ()
withArduino Bool
False FilePath
"/dev/cu.usbmodemFD131" (Arduino () -> IO ()) -> Arduino () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
Pin -> PinMode -> Arduino ()
setPinMode Pin
led PinMode
OUTPUT
Pin -> PinMode -> Arduino ()
setPinMode Pin
pot PinMode
ANALOG
cur <- Pin -> Arduino Int
analogRead Pin
pot
liftIO $ print cur
go cur
where led :: Pin
led = Word8 -> Pin
digital Word8
13
pot :: Pin
pot = Word8 -> Pin
analog Word8
3
go :: Int -> Arduino b
go Int
cur = do Pin -> Bool -> Arduino ()
digitalWrite Pin
led Bool
True
Int -> Arduino ()
delay Int
cur
Pin -> Bool -> Arduino ()
digitalWrite Pin
led Bool
False
Int -> Arduino ()
delay Int
cur
new <- Pin -> Arduino Int
analogRead Pin
pot
when (cur /= new) $ liftIO $ print new
go new