Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
limchengwei
Published

MCP23017 blink without delay

Thank you JLCPCB for making this project a success. This project uses 8 MCP23017 which can provide 128 inputs or outputs.

IntermediateWork in progress3 hours471
MCP23017 blink without delay

Things used in this project

Hardware components

JLCPCB Customized PCB
JLCPCB Customized PCB
×3
Female/Female Jumper Wires
Female/Female Jumper Wires
×160
mcp23017 board
×8
Arduino Mega 2560
Arduino Mega 2560
×1
ch340g
×1
Male Header 80 Position 2 Row (0.1")
Male Header 80 Position 2 Row (0.1")
×10
female header 16 position 2 row (0.1")
×10
Female Header 20 Position 2 Row (0.1")
Female Header 20 Position 2 Row (0.1")
×10
Male Header 40 Position 1 Row (0.1")
Male Header 40 Position 1 Row (0.1")
×10
female header 10 position 1 row (0.1")
×10
female header 3 position 1 row (0.1")
×100
LED (generic)
LED (generic)
×130
ttp223 touch sensor
×100
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

MCP23017 PCB

PCB

LED bar PCB

PCB

Piano PCB

PCB

Gerber PCB 8 MCP23017

Gerber

Gerber PCB LED bar

Gerber

Gerber PCB Piano touch sensor

Gerber

Schematics

Schematic 8 MCP23017

Schematic LED bar

Schematic Piano touch sensor

Schematic 8 MCP23017 EasyEDA

EasyEDA

Schematic LED bar EasyEDA

EasyEDA

Schematic Piano touch sensor EasyEDA

EasyEDA

Code

MCP23017_Piano.zip

Arduino
Arduino
No preview (download only).

MCP23017_LEDs.ino

Arduino
Arduino
#include "Adafruit_MCP23017.h"
Adafruit_MCP23017 mcp[8];
int i, j, state = 0;
unsigned long current_time, previous_time = 0;

void setup()
{
  for (j=0; j<8; j++)
  {
    mcp[j].begin(j);
  }
  for(j=0; j<8; j++)
  {
    for(i=0; i<16; i++)
    {
      mcp[j].pinMode(i, OUTPUT);
    }
  }
}

void loop()
{
  for (j=0; j<8; j++)
  {
    state = 0;
    while (state != 2)
    {
      current_time = millis();
      if (current_time - previous_time >= 500)
      {
        previous_time = current_time;
        if (state == 0)
        {
          state = 1;
          for (i=0; i<16; i++)
          {
            mcp[j].digitalWrite (i, state);
          }
        }
        else if (state == 1)
        {
          state = 0;
          for (i=0; i<16; i++)
          {
            mcp[j].digitalWrite (i, state);
          }
          state = 2;
        }
      }
    }
  }
}

Credits

limchengwei
24 projects • 4 followers

Comments