open System.Threading
open RaspberryPiDotNet
module Buttons =
let SW = [| new GPIOMem(GPIOPins.V2Plus_Pin_P1_38);
new GPIOMem(GPIOPins.V2Plus_Pin_P1_37);
new GPIOMem(GPIOPins.V2Plus_Pin_P1_40)|]
for i = 0 to SW.Length-1 do
SW.[i].PinDirection <- GPIODirection.In
let value n = SW.[n].Read()
let waitButton() =
let mutable on = true
let mutable n = -1
while on=true do
for i = 0 to SW.Length-1 do
if SW.[i].Read() = PinState.Low then
on <- false
n <- i
Thread.Sleep(100)
n
let LED = [|new GPIOMem(GPIOPins.V2_Pin_P1_22)
new GPIOMem(GPIOPins.V2_Pin_P1_18)
new GPIOMem(GPIOPins.V2_Pin_P1_16)
new GPIOMem(GPIOPins.V2_Pin_P1_12)|]
for i = 0 to SW.Length-1 do
LED.[i].PinDirection <- GPIODirection.Out
let Write (n, state:PinState) =
LED.[n].Write(state)
let clear() =
for i=0 to LED.Length-1 do
LED.[i].Write(PinState.Low)
while true do
Buttons.clear()
let x= Buttons.waitButton()
if x <> -1 then
Buttons.Write (x, PinState.High)
Thread.Sleep(300)
Buttons.Write (x, PinState.Low)
|
1
2
3
4 ボタンスイッチのクラス
5 ボタンスイッチのオブジェクトの配列
6
7
8
9 スイッチのポートを入力に設定
10
11 スイッチの状態を入力する
12 スイッチが押されるのを待ち
13 どのスイッチが押されたか報告
14
15
16
17
18
19
20
21
22 LEDオブジェクトの配列
23
24
25
26
27 ポートを出力に設定
28 n番目のLEDを点灯/消灯
29
30 全てのLEDを消灯
31
32
33
34 永久ループ
35 全てのLEDを消灯
36 押されたボタンを知る
37
38 押された番号のLED点灯
39
40 押された番号のLED消灯
|