1 Commits

Author SHA1 Message Date
oracle 3b01017ad0 boot v2 2026-06-16 22:17:33 -04:00
+34 -12
View File
@@ -1,7 +1,7 @@
// =============================================================================
// Auth: dodd
// Auth: alex
// File: boot.go
// Revn: 06-23-2022 0.1
// Revn: 06-16-2026 2.0
// Func: Blink a light when the pi boots (or on login, but who cares)
//
// TODO: create
@@ -9,6 +9,11 @@
// CHANGE LOG
// -----------------------------------------------------------------------------
// 06-23-2022: init
//*10-10-2023: imported flag
// added flag to define gpio pin at runtime
//*06-16-2026: added flag to control flash duration
// added flag to control amount of flashes
// added flag to decide between flash mode and toggle mode
//
// =============================================================================
@@ -16,10 +21,12 @@ package main
import (
"fmt"
"flag" // IntVar, BoolVar, Float64Var, Parse
"fmt" // Println
// rpio.Pin, Pin, Open, Close, Output, Toggle
"github.com/stianeikeland/go-rpio"
"os"
"time"
"os" // Exit
"time" // Sleep, time.Second
)
@@ -29,13 +36,23 @@ Connect a LED with resistor from pin 19 to ground.
*/
// Use mcu pin 10, corresponds to physical pin 19 on the pi
var pin rpio.Pin
var pin rpio.Pin // global pin object
var num int // flag variable, holds pin number
var dur float64 // flag variable, holds duration
var amt int // flag variable, holds times to flash
var tog bool // flag variable, hold toggle mode switch
func main() {
pin = rpio.Pin( 10 )
// map input flag to variable
flag.IntVar( &num, "p", 10, "pin number" )
flag.Float64Var( &dur, "d", 100, "duration of flash (ms)" )
flag.IntVar( &amt, "n", 2, "amount of times to flash" )
flag.BoolVar( &tog, "t", false, "toggle mode" )
flag.Parse()
// create pin object at given pin number
pin = rpio.Pin( num )
// Open and map memory to access gpio, check for errors
if err := rpio.Open(); err != nil {
fmt.Println( "Fatal: pin open failed" )
@@ -49,10 +66,15 @@ func main() {
// Set pin to output mode
pin.Output()
// Toggle pin 2 times
for i := 0; i < 4; i++ {
if tog { // if user specifies toggle mode
pin.Toggle() // toggle
return // and leave
}
// Toggle pin 2*amt times
for i := 0; i < 2 * amt; i++ {
pin.Toggle()
time.Sleep(time.Second / 10)
time.Sleep( time.Millisecond * time.Duration( dur ) )
}
}