# Play beep at shutdown
import smbus, time

encoding = 'utf-8'

MCP23008_REG_IODIR   = 0x00 # I/O DIRECTION Register
MCP23008_REG_GPIO    = 0x09 # GENERAL PURPOSE I/O PORT Register
# I2C channel 1 is connected to the GPIO pins
channel = 1

#  GPIO expander
address = 0x20

bus = smbus.SMBus(channel)

bus_data = bus.read_byte_data(address, MCP23008_REG_GPIO)
bus.write_byte_data(address, MCP23008_REG_IODIR, 0x00)
bus.write_byte_data(address, MCP23008_REG_GPIO, bus_data | 0x01)
time.sleep(0.05)
bus.write_byte_data(address, MCP23008_REG_GPIO, bus_data & 0xFE)

bus.close()
