package led import ( "sync" "time" ) const ( DurationFlick = 40 * time.Millisecond ) type LEDController struct { led1 bool led2 bool mu1 sync.Mutex mu2 sync.Mutex } func NewLEDController() *LEDController { var controller LEDController controller.led1 = false controller.led2 = false return &controller } // turn both off func (c *LEDController) Off() { c.led1 = true c.led2 = true c.Disable1() c.Disable2() } func (c *LEDController) Enable1() { if c.led1 { return } c.led1 = true // gpio code to turn LED 1 on } func (c *LEDController) Enable2() { if c.led2 { return } c.led2 = true // gpio code to turn LED 2 on } func (c *LEDController) Disable1() { if !c.led1 { return } c.led1 = false // gpio code to turn LED 1 off } func (c *LEDController) Disable2() { if !c.led2 { return } c.led2 = false // gpio code to turn LED 2 off } func (c *LEDController) Flick1() { c.mu1.Lock() defer c.mu1.Unlock() // assume it is off c.Enable1() time.Sleep(DurationFlick) c.Disable1() } func (c *LEDController) Flick2() { c.mu2.Lock() defer c.mu2.Unlock() // assume it is off c.Enable2() time.Sleep(DurationFlick) c.Disable2() }