Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b01017ad0 |
+34
-12
@@ -1,7 +1,7 @@
|
|||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Auth: dodd
|
// Auth: alex
|
||||||
// File: boot.go
|
// 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)
|
// Func: Blink a light when the pi boots (or on login, but who cares)
|
||||||
//
|
//
|
||||||
// TODO: create
|
// TODO: create
|
||||||
@@ -9,6 +9,11 @@
|
|||||||
// CHANGE LOG
|
// CHANGE LOG
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// 06-23-2022: init
|
// 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 (
|
import (
|
||||||
"fmt"
|
"flag" // IntVar, BoolVar, Float64Var, Parse
|
||||||
|
"fmt" // Println
|
||||||
|
// rpio.Pin, Pin, Open, Close, Output, Toggle
|
||||||
"github.com/stianeikeland/go-rpio"
|
"github.com/stianeikeland/go-rpio"
|
||||||
"os"
|
"os" // Exit
|
||||||
"time"
|
"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 // global pin object
|
||||||
var pin rpio.Pin
|
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() {
|
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
|
// Open and map memory to access gpio, check for errors
|
||||||
if err := rpio.Open(); err != nil {
|
if err := rpio.Open(); err != nil {
|
||||||
fmt.Println( "Fatal: pin open failed" )
|
fmt.Println( "Fatal: pin open failed" )
|
||||||
@@ -49,10 +66,15 @@ func main() {
|
|||||||
// Set pin to output mode
|
// Set pin to output mode
|
||||||
pin.Output()
|
pin.Output()
|
||||||
|
|
||||||
// Toggle pin 2 times
|
if tog { // if user specifies toggle mode
|
||||||
for i := 0; i < 4; i++ {
|
pin.Toggle() // toggle
|
||||||
|
return // and leave
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle pin 2*amt times
|
||||||
|
for i := 0; i < 2 * amt; i++ {
|
||||||
pin.Toggle()
|
pin.Toggle()
|
||||||
time.Sleep(time.Second / 10)
|
time.Sleep( time.Millisecond * time.Duration( dur ) )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user