7 Segments - code
Help me by sharing this post

Below you have the code for the 7 segments display test. The code will hAve a few examples to show characters, numbers and also control each segment separatelly. We have two voids for that. One is to show an entire character or number and the other is to control each segment separatelly. Downlaod the code from below and also the Adafruit library from the next link.








schematic DIY 7-segments display



/*  7 segment display with WS2811 drivers example code
 *   By ELECTRONOOBS
 *   Tutorial: https://electronoobs.com/eng_arduino_tut108.php
 *   Scheamtic: Tutorial: https://electronoobs.com/eng_arduino_tut108_sch1.php
 *   Code: Tutorial: https://electronoobs.com/eng_arduino_tut108_code1.php
 *   PCB: Tutorial: https://electronoobs.com/eng_arduino_tut108_gerber1.php
 */

#include <Adafruit_NeoPixel.h>        //Download it here: https://www.electronoobs.com/eng_arduino_Adafruit_NeoPixel.php
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN            6      //Pin for serial data
#define NUMMODULES     2      //Amount of modules (7 seg displays)
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMMODULES*3, PIN, NEO_GRB + NEO_KHZ800);

//Variables
int delay_time = 40;


void setup() {  
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code
  pixels.begin(); // This initializes the NeoPixel library.
}



void loop() { 


//Example 1
//Could show 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and a  b  c  d  e  f  h  l  o  p  s  u  x(DP)
show_char(0,0);       //module 0 show a 0
show_char(1,'a');     //module 1 show the A
delay(delay_time);    
show_char(0,1);       //module 0 show a 1
show_char(1,'b');     //so on...
delay(delay_time);
show_char(0,2);
show_char(1,'c');
delay(delay_time);
show_char(0,3);
show_char(1,'d');
delay(delay_time);
show_char(0,4);
show_char(1,'f');
delay(delay_time);
show_char(0,5);
show_char(1,'h');
delay(delay_time);
show_char(0,6);
show_char(1,'l');
delay(delay_time);
show_char(0,7);
show_char(1,'o');
delay(delay_time);
show_char(0,8);
show_char(1,'p');
delay(delay_time);
show_char(0,9);
show_char(1,'s');
delay(delay_time);


//Example 2
//Could control each segment separatelly from A to G and the DP
show_segment(0,'a');    //Turn on segment A from module 0
show_segment(1,'f');    //Turn on segment F from module 1
delay(delay_time);
show_segment(0,'b');    //And so on...
show_segment(1,'e');
delay(delay_time);
show_segment(0,'c');
show_segment(1,'d');    
delay(delay_time);
show_segment(0,'d');
show_segment(1,'c');
delay(delay_time);
show_segment(0,'e');
show_segment(1,'b');
delay(delay_time);
show_segment(0,'f');
show_segment(1,'a');
delay(delay_time);   

}


void show_segment(int module, int segment)
{
  int num_led = module*3;
  switch (segment)
  {
    case 'a':
    pixels.setPixelColor(num_led, pixels.Color(255,0,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    case 'b':
    pixels.setPixelColor(num_led, pixels.Color(0,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    case 'c':
    pixels.setPixelColor(num_led, pixels.Color(255,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    case 'd':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,0,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    case 'e':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    case 'f':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    case 'g':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;
    case 'x':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(0,255,255));  //DP  G  NC
    break;
  }
  
  pixels.show();
}








void show_char(int module, char character)
{
  int num_led = module*3;
  switch (character)
  {

    case 0:
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    
    case 1:
    pixels.setPixelColor(num_led, pixels.Color(0,255,0));  //B  A  C  
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
      
    case 2:
    pixels.setPixelColor(num_led, pixels.Color(0,0,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 3:
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,0,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 4:
    pixels.setPixelColor(num_led, pixels.Color(0,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 5:
    pixels.setPixelColor(num_led, pixels.Color(255,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 6:
    pixels.setPixelColor(num_led, pixels.Color(255,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 7:
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;

    case 8:
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 9:
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'a':
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,255,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'b':
    pixels.setPixelColor(num_led, pixels.Color(255,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'c':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'd':
    pixels.setPixelColor(num_led, pixels.Color(0,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'e':
    pixels.setPixelColor(num_led, pixels.Color(255,0,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'f':
    pixels.setPixelColor(num_led, pixels.Color(0,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'h':
    pixels.setPixelColor(num_led, pixels.Color(0,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,255,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'l':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;

    case 'o':
    pixels.setPixelColor(num_led, pixels.Color(255,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'p':
    pixels.setPixelColor(num_led, pixels.Color(0,0,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,255,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 's':
    pixels.setPixelColor(num_led, pixels.Color(255,0,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,0,255));  //DP  G  NC
    break;

    case 'u':
    pixels.setPixelColor(num_led, pixels.Color(0,255,0));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(0,0,0));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;

    case 'x':
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(0,255,255));  //DP  G  NC
    break;

    
    
    default:
    pixels.setPixelColor(num_led, pixels.Color(255,255,255));  //B  A  C 
    pixels.setPixelColor(num_led+1, pixels.Color(255,255,255));  //E  D  F
    pixels.setPixelColor(num_led+2, pixels.Color(255,255,255));  //DP  G  NC
    break;
    
  }
  pixels.show();
}








yt_link
insta_link
fb_link
twitter_link

7 Segments


PCBWAY PCB service

PCBWAY PCB service

PCBWAY PCB service