Beispiel #1
0
// do_blink listens on the provided channel for specified color and blinks it at an
// interval.
func do_blink(color <-chan byte) {
	var c byte
	var intensity byte

	tick := time.NewTicker(BLINK_INTERVAL)

LOOP:
	for {
		select {
		case c_new, ok := <-color:
			if !ok {
				break LOOP
			}
			piglow.Ring(c, 0)
			c = c_new
		case <-tick.C:
			if intensity == 0 {
				intensity = INTENSITY_MAX
			} else {
				intensity = 0
			}
			piglow.Ring(c, intensity)
		}
	}
	err := piglow.ShutDown()
	if err != nil {
		log.Printf("failed to shutdown piglow: %v", err)
	}
}
Beispiel #2
0
// displayUtilization takes a utilization percentage (between 0 and 1.0) and a
// brightness percentage (between 0 and 1.0) and displays them via the PiGlow's
// rings. 0% utilization -> no LEDs lit up. 50% utilization -> half the LEDs lit
// up, starting in the center. 100% utilization -> all LEDs lit up.
func displayUtilization(utilization float64, brightness float64) {
	brightnessByte := byte(math.Floor(brightness*255.0 + 0.5))

	// Using 6 here instead of 5 so no LEDs are lit for no utilization.
	lastRing := 6 - int(math.Floor(utilization*6.0+0.5))

	for ring := 0; ring <= 5; ring++ {
		if ring >= lastRing {
			piglow.Ring(byte(ring), brightnessByte)
		} else {
			piglow.Ring(byte(ring), 0x00)
		}
	}
}