Hi, After reading golang's tutorials on the wiki. I feel interesting about golang.So I try to do something. ====According to the temperature control fan speed=== Here are the main codes: package main import ( "fmt" "time" "github.com/tjCFeng/GoRK3288/RK3288" ) func main() { defer RK3288.FreeRK3288() PWM1, _ := RK3288.CreatePWM(RK3288.PWM_1) PWM1.SetInactivePolarity(RK3288.Positive) PWM1.SetPERIOD(50000) PWM1.SetDUTY(0) PWM1.SetCNT(0) PWM1.Start() for{ time.Sleep(time.Second * 1) _, Data, _, _ := RK3288.ITSADC().GetData() var adc_date = RK3288.ITSADC().GetTemperature(Data) fmt.Println("Temperature:",adc_date) fmt.Println("Period:",50000) if adc_date <= 40{ PWM1.Stop() PWM1.SetPERIOD(50000) PWM1.SetDUTY(50000) PWM1.SetCNT(0) PWM1.Start() fmt.Println("Duty:",0) }else if adc_date >= 40 || adc_date <= 60{ PWM1.Stop() PWM1.SetPERIOD(50000) PWM1.SetDUTY(50000-(uint32)(adc_date) * 766) PWM1.SetCNT(0) PWM1.Start() fmt.Println("Duty:",(50000-(uint32)(adc_date) * 766)) }else if adc_date >= 60{ PWM1.Stop() PWM1.SetPERIOD(50000) PWM1.SetDUTY(0) PWM1.SetCNT(0) PWM1.Start() fmt.Println("Duty:",50000) } } }
|