This is a creation in Article, where the information may have evolved or changed.
This program achieves LED blink in Raspberry Pi with Go lang.//This is the implemented with Hard-coding and uses only main Function.package mainimport ("FMT" "OS" "Time") Func main () {//Initialize GPIO25 FMT . Println ("Initialize GPIO25") fd, ERR: = OS. OpenFile ("/sys/class/gpio/export", OS. O_wronly|os. O_sync, 0666) if err! = Nil {fmt. PRINTLN ("Open/sys/class/gpio/export fails") FMT. PRINTLN (ERR) return} FMT. Fprint (FD, "+") fd. Close ()//Check iinitialization result fmt. PRINTLN ("Check initialization Result") _, err = OS. Stat ("/sys/class/gpio/gpio25") if err! = Nil {fmt. Println ("Export GPIO25 fails") FMT. PRINTLN (Err)} else {fmt. Println ("Export GPIO25 succeeds")}//Set direction to-out FMT. Println ("Set direction of GPIO25 to Out") fd, err = os. OpenFile ("/sys/clasS/gpio/gpio25/direction ", Os. O_wronly|os. O_sync, 0666) if err! = Nil {fmt. PRINTLN ("open/sys/class/gpio/gpio25/direction fails") FMT. PRINTLN (Err)} FMT. Fprint (FD, "out") fd. Close ()//Start blink FMT. Println ("Start blink") for I: = 0; I < 20; i++ {FD, err: = OS. OpenFile ("/sys/class/gpio/gpio25/value", OS. O_wronly|os. O_sync, 0666) if err! = Nil {fmt. PRINTLN ("Open/sys/class/gpio/gpio25/value fails") FMT. PRINTLN (ERR)} if i%2 = = 1 {//Turn on LED FM T.fprint (FD, 1)} else {//Turn off LED fmt. Fprint (FD, 0)} FD. Close () time. Sleep (Time.millisecond)}//End FMT. PRINTLN ("Start finalizing") fd, err = os. OpenFile ("/sys/cLass/gpio/gpio25/value ", Os. O_wronly|os. O_sync, 0666) if err! = Nil {fmt. PRINTLN ("Open/sys/class/gpio/gpio25/value fails") FMT. PRINTLN (ERR)}//Turn off LED fmt. Println ("Turn off LED") fmt. Fprint (FD, 0) fd. Close () fd, err = os. OpenFile ("/sys/class/gpio/unexport", OS. O_wronly|os. O_sync, 0666) if err! = Nil {fmt. PRINTLN ("Open/sys/class/gpio/unexport fails") FMT. PRINTLN (ERR) return} FMT. Fprint (FD, "+") fd. Close () fmt. PRINTLN ("End finalizing")}
Http://shang.qq.com/wpa/qunwpa?idkey=912ee9f1c4d48fd64877a62ce321ca041ff6780dee63a5ccaa07241719ea5be9 Multi-language/ High Concurrency Research group