Esempio n. 1
0
func main() {

	// creates a new MCP23S17 instance
	mcp := MCP23S17.NewMCP23S17(spi.DEFAULT_HARDWARE_ADDR, spi.DEFAULT_BUS, spi.DEFAULT_CHIP)

	// GPIOa outputs
	gpioa := make([]*MCP23S17.MCP23S17RegisterBit, 8)
	for i := range gpioa {
		gpioa[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, mcp)
	}

	// Connects to chip
	err := mcp.Open()
	if err != nil {
		log.Fatalf("Error connecting to chip: %s\n", err)
	}

	// Blinks output 7
	for {
		gpioa[7].Toggle()
		time.Sleep(time.Second)
	}
}
Esempio n. 2
0
// Create a new PiFaceDigital Instance
func NewPiFaceDigital(hardware_addr byte, bus int, chip_select int) *PiFaceDigital {
	pfd := new(PiFaceDigital)
	pfd.mcp = MCP23S17.NewMCP23S17(hardware_addr, bus, chip_select)
	// pfd.device = interrupts.NewGPIOInterruptDevice()

	pfd.InputPins = make([]*MCP23S17.MCP23S17RegisterBitNeg, 8)
	for i := range pfd.InputPins {
		pfd.InputPins[i] = MCP23S17.NewMCP23S17RegisterBitNeg(uint(i), MCP23S17.GPIOB, pfd.mcp)
	}

	pfd.InputPort = MCP23S17.NewMCP23S17RegisterNeg(MCP23S17.GPIOB, pfd.mcp)

	pfd.OutputPins = make([]*MCP23S17.MCP23S17RegisterBit, 8)
	for i := range pfd.OutputPins {
		pfd.OutputPins[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, pfd.mcp)
	}

	pfd.OutputPort = MCP23S17.NewMCP23S17Register(MCP23S17.GPIOA, pfd.mcp)

	pfd.Leds = make([]*MCP23S17.MCP23S17RegisterBit, 8)
	for i := range pfd.Leds {
		pfd.Leds[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, pfd.mcp)
	}

	pfd.Relays = make([]*MCP23S17.MCP23S17RegisterBit, 2)
	for i := range pfd.Relays {
		pfd.Relays[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, pfd.mcp)
	}

	pfd.Switches = make([]*MCP23S17.MCP23S17RegisterBit, 4)
	for i := range pfd.Switches {
		pfd.Switches[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOB, pfd.mcp)
	}

	return pfd
}