This is a creation in Article, where the information may have evolved or changed.
/*
# date:2016-11-10
# Author:simonzhang
# web:www.simonzhang.net
# email:simon-zzm@163.com
*/
Package Main
Import (
"OS"
"Github.com/stianeikeland/go-rpio"
"Time"
)
VAR (
AIO = Rpio. Pin (14)
Fio = Rpio. Pin (4)
Alertcount int = 0
)
Fan Port
Func fWrite (status string) {
Fio. Output ()
If status = = "High" {
Fio. High ()
}else if status = = "Low" {
Fio. Low ()
}
}
Monitoring port
Func aread () int{
Aio. Input ()
return int (AIO. Read ())
}
Func Main () {
ERR: = Rpio. Open ()
If err! = Nil {
Os. Exit (1)
}
Defer Rpio. Close ()
Because there is no while directly with the for
for {
Numbers can't be too big.
1 is a memory problem, 2 is the Stop fan range
If aread () = = 1 {
If Alertcount > 0{
Alertcount-= 1
}
}else{
If Alertcount <= 10{
Alertcount + = 1
}
}
Print (Alertcount, "", Aread (), "\ n")
//
If Alertcount > 3{
FWrite ("High")
} else {
FWrite ("Low")
}
Wait one second per cycle
Time. Sleep (Time.millisecond)
}
}