WIP first draft of terraforming script
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// =============================================================================
|
||||
// Auth: Alex Celani
|
||||
// File: boot.go
|
||||
// Revn: 10-10-2023 1.0
|
||||
// Func: Blink a light when the pi boots (or on login, but who cares)
|
||||
//
|
||||
// TODO: create
|
||||
// =============================================================================
|
||||
// CHANGE LOG
|
||||
// -----------------------------------------------------------------------------
|
||||
// 06-23-2022: init
|
||||
// 10-10-2023: imported flag
|
||||
// added flag to define gpio pin at runtime
|
||||
//
|
||||
// =============================================================================
|
||||
|
||||
package main
|
||||
|
||||
|
||||
import (
|
||||
"flag" // IntVar, Parse
|
||||
"fmt" // Println
|
||||
// rpio.Pin, Pin, Open, Close, Output, Toggle
|
||||
"github.com/stianeikeland/go-rpio"
|
||||
"os" // Exit
|
||||
"time" // Sleep, time.Second
|
||||
)
|
||||
|
||||
|
||||
/*
|
||||
Toggles a LED on physical pin 19 (mcu pin 10)
|
||||
Connect a LED with resistor from pin 19 to ground.
|
||||
*/
|
||||
|
||||
|
||||
var pin rpio.Pin // global pin object
|
||||
var num int // flag variable, holds pin number
|
||||
|
||||
|
||||
func main() {
|
||||
|
||||
// map input flag to variable
|
||||
flag.IntVar( &num, "p", 10, "pin number" )
|
||||
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" )
|
||||
fmt.Println( "Error: ", err.Error() )
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Unmap gpio memory when done
|
||||
defer rpio.Close()
|
||||
|
||||
// Set pin to output mode
|
||||
pin.Output()
|
||||
|
||||
// Toggle pin 2 times
|
||||
for i := 0; i < 4; i++ {
|
||||
pin.Toggle()
|
||||
time.Sleep(time.Second / 10)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user