本帖最后由 madman 于 2015-5-28 09:13 编辑
之前看到论坛上tjCFeng的go语言教程,写得很有意思,然后就想试试。就照着wiki上的教程搭建好了编译环境。下载了tjCFeng的gork3288库,然后发现温度和pwm都有,于是我就想到将之前的根据cpu温度控制风扇移植过来。因为【GoRK3288】库里的函数都封装好了,还有教程。所以试了下就出来了,不过里面的pwm默认设置是高电平的。发现go语言还是很方便的,而且跟c挺像的,会点c基本上就可以直接开始用来写点简单的东西了。功能跟之前的驱动那个是一样的(ps:不过省事多了~~),下面附上代码: 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:",50000) }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:",0) }
}
}
|