limchengwei
Published © CC BY

MCP23017 blink without delay

This Printed Circuit Board project is sponsored by JLCPCB. The MCP23017 PCB consists of 8 16-Bit I/O Expander with Serial Interface.

IntermediateFull instructions provided3 hours486
MCP23017 blink without delay

Things used in this project

Hardware components

JLCPCB Customized PCB
JLCPCB Customized PCB
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×40
Jumper wires (generic)
Jumper wires (generic)
×40
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
mcp23017so
×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")
×3
Female Header 20 Position 2 Row (0.1")
Female Header 20 Position 2 Row (0.1")
×1

Hand tools and fabrication machines

Hot Air Station, Industrial
Hot Air Station, Industrial
Solder Paste, Cartridge
Solder Paste, Cartridge
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Custom parts and enclosures

Gerber

Schematics

Schematics

EasyEDA

Code

MCP23017_1_to_8.1.ino

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

Credits

limchengwei

limchengwei

24 projects • 4 followers

Comments