Ejemplo n.º 1
0
func Example() {
	p, err := piglow.Open(&i2c.Devfs{Dev: "/dev/i2c-1"})
	if err != nil {
		panic(err)
	}

	if err := p.Setup(); err != nil {
		panic(err)
	}

	brightness := uint8(0)
	allLEDs := piglow.All.LEDs()
	for i := 0; i < 10; i++ {
		brightness ^= 1
		p.SetBrightness(allLEDs, brightness)
		time.Sleep(300 * time.Millisecond)
	}
}
Ejemplo n.º 2
0
func main() {
	p, err := piglow.Open(&i2c.Devfs{Dev: "/dev/i2c-1"})
	if err != nil {
		panic(err)
	}
	defer p.Close()

	time.Sleep(50 * time.Millisecond)
	for i := piglow.LED(0); i < piglow.NumLEDs; i++ {
		if err := p.SetBrightness(i.LEDs(), 1); err != nil {
			panic(err)
		}
		time.Sleep(10 * time.Millisecond)
	}

	time.Sleep(50 * time.Millisecond)
	for i := piglow.LED(piglow.NumLEDs - 1); i >= 0; i-- {
		if err := p.SetBrightness(i.LEDs(), 0); err != nil {
			panic(err)
		}
		time.Sleep(10 * time.Millisecond)
	}
}
Ejemplo n.º 3
0
func main() {
	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, `Usage: piglow [flags] level group|operator...`)
		fmt.Fprintln(os.Stderr, "\nFlags:")
		flag.PrintDefaults()
		fmt.Fprint(os.Stderr, `

The piglow command sets a set of PiGlow LEDs to the given
level (0-255).

Each argument after the level operates on a stack, each element
of which holds a set of LEDs. Elements are added by proceeding
through all the arguments in sequence. After all arguments are
processed, the union of all LEDs in the stack will be set.

The following arguments are recognized:

	all - all the LEDs.
	<color name> - all the LEDs with the given color.
	<number> - the LED with the given number (0..17)
	r<number> - all LEDs the given radius from the centre (0..6)
	arm<number> - all LEDs in the given arm (0..2)
	<number>..<number> - all LEDs in the given numeric range
	r<number>..r<number> - all LEDs in the given radius range
	+ - the union of the top two stack elements
	- - the difference of the top two stack elements
	. - the intersection of the top two stack elements

For example:

	piglow 50 arm1 red white + .

will set the red and white LEDs on arm 1 to level 50.

	piglow 10 all white -

will set all except the white LEDs to level 10.
`[1:])
		os.Exit(1)
	}
	flag.Parse()
	if flag.NArg() < 1 {
		flag.Usage()
	}
	p, err := piglow.Open(&i2c.Devfs{Dev: "/dev/i2c-1"})
	if err != nil {
		log.Fatalf("cannot open: %v", err)
	}
	if *reset {
		if err := p.Setup(); err != nil {
			log.Fatalf("cannot reset: %v", err)
		}
	}
	levelStr := flag.Arg(0)
	level, err := strconv.Atoi(levelStr)
	if err != nil || level < 0 || level >= 256 {
		log.Fatalf("invalid level %q", levelStr)
	}
	var stack []piglow.Set
	for _, arg := range flag.Args()[1:] {
		if op := ops[arg]; op != nil {
			stack1, err := op(stack)
			if err != nil {
				log.Fatalf("operation %q: %v", arg, err)
			}
			stack = stack1
		} else {
			g, err := piglow.ParseGroup(arg)
			if err != nil {
				log.Fatal(err)
			}
			stack = append(stack, g.LEDs())
		}
	}
	var set piglow.Set
	for _, s := range stack {
		set |= s
	}
	if err := p.SetBrightness(set, uint8(level)); err != nil {
		log.Fatal(err)
	}
}