#!/usr/bin/python

from Adafruit_I2C import Adafruit_I2C
from MCP23017 import MCP23017

import time

mcp_r = MCP23017(address = 0x20, num_gpios = 16) # MCP23017

for pin in range (0,16):
        mcp_r.pinMode(pin, mcp_r.OUTPUT)


while True:
	time1=int(round(time.time() * 1000))
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1, pressed"
        time.sleep(2/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0"
        time.sleep(2/1000.0)
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(2/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0"
        time.sleep(2/1000.0)
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(2/1000.0)

        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(10/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0"
        time.sleep(10/1000.0)
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(10/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0"
        time.sleep(10/1000.0)

        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1, pressed"
        time.sleep(0.2) #pressed

        time.sleep(2/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0, released"
        time.sleep(2/1000.0)
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(2/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0"
        time.sleep(2/1000.0)
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(2/1000.0)

        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(10/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0"
        time.sleep(10/1000.0)
        mcp_r.output(3, 1)
	print str(int(round(time.time() * 1000))-time1)+" 1"
        time.sleep(10/1000.0)
        mcp_r.output(3, 0)
	print str(int(round(time.time() * 1000))-time1)+" 0, released"
        time.sleep(10/1000.0)

        time.sleep(10)
