Driving an Adafruit 7-Segment display

Use the sketch here to drive an Adafruit 7-segment LED display. The example sketch runs through a number of examples to demonstrate how to code different outputs as follows:

  1. integer
  2. hexadecimal
  3. floating point
  4. a number that is too large for the display - display shows ----
  5. illuminate the dots individually, then the colon
  6. animated snake

There's more information on how illuminate individual LED segments using writeDataRaw().

/*******************************************************************************
* es-seven-segment     V1.0 12-Jul-2018 JST Lawrence.                          *
*                                                                              *
* Purpose: demonstrate ESP8266 driving Adafruit 7-segment display over I2C.    *
*                                                                              *
* Works with Adafruit devices 878, 879, 880 and 881 from adafruit.com          *
*******************************************************************************/

#include <Wire.h>

#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix = Adafruit_7segment();

// The numbers are GPIO pin numbers to be used for I2C
#define SCL 0
#define SDA 4

void setup()
{

// Initialise I2C
  Wire.begin(SDA,SCL);

// Set up LED at 0x70 - change address as required
  matrix.begin(0x70);
}

void loop()
{
  int i,snake[]={3,6,12,24,48,33,0};
  char Str[4];

// print an integer
  matrix.print(4321, DEC);
  matrix.writeDisplay();
  delay(1500);

// print a hex number
  matrix.print(0xBEEF, HEX);
  matrix.writeDisplay();
  delay(1500);

// print a floating point 
  matrix.print(12.34);
  matrix.writeDisplay();
  delay(1500);

// try to print a number thats outside the range -999 to 9999
  matrix.print(10000, DEC);
  matrix.writeDisplay();
  delay(1500);

// Show dots and colon
  matrix.clear();              // everything off
  matrix.writeDigitRaw(0,128); // first dot
  matrix.writeDisplay();
  delay(1500);
  matrix.writeDigitRaw(1,128); // second dot
  matrix.writeDisplay();
  delay(1500);
  matrix.writeDigitRaw(3,128); // third dot
  matrix.writeDisplay();
  delay(1500);
  matrix.writeDigitRaw(4,128); // fourth dot
  matrix.writeDisplay();
  delay(1500);
  matrix.clear();              // everything off
  matrix.drawColon(1);         // colon
  matrix.writeDisplay();
  delay(1500);

// Rotating snake
  matrix.clear();              // everything off
  while(1)
  { for(i=0;i<6;i++)
    { matrix.writeDigitRaw(0, snake[i]);
      matrix.writeDigitRaw(1, snake[i]);
      matrix.writeDigitRaw(3, snake[i]);
      matrix.writeDigitRaw(4, snake[i]);
      matrix.writeDisplay();
      delay( 100);
    }
  }

}


The Fritzing diagram below shows the connections to the ESP8266. Adafruit 7-segment LED and connection to ESP8266

Do this with an Arduino.