Building Your First Ever 7-Segment Project CloudX

  • img
Project Details

 

 

 

Let's learn how to use the very popular 7-segment display. Here, we’ll be using the display for a simple up-and-down counter. The circuit connection is quite simple to implement; and we’ll be making use of the breadboard and a simple CloudX code to realize the project.

 

Meanwhile ─so far, we've learned how to blink a simple LED via CloudX's output, and how to proceed further to incorporating the CloudX digital input in using a switch to control LED on and off states. In this lesson, we'll control the up and down single digit counting operation, (which has a range of between 0 and 9), using a two switch arrangement.

List Of Materials Needed 

(The material full kit can readily be sourced via this link.)

  • (i)   CloudX Microcontroller and Softcard
  • (ii)   7-Segment Display
  • (iii)  2 Push Button Switches
  • (iv)  Resistor:
  1. •   any value from 100Ω – 1kΩ
  2. •   10kΩ  x 2 units
Material Kit

 

 

                   Step 1: Hints and Brief Overview

 

7-Segment Display Unit

The 7-segment is simply nothing more than an LED display whereby 7 LEDs are properly arranged and molded together in a rectangular shape to form an electronic display unit. It finds wide applications in symbol display, with an extra dp LED for display of decimal point. The combined 8 LEDs are labeled as thus:

7-Segment Label

The component LEDs making up a given display unit typically have either their Anode or Cathode pins ganged together to a common pin; to form a Common-Anode or Common-Cathode 7-segment.

7-Segment Common Cathode

Hints:

  • (i) The pin-outs are typically not as straight forward as the segment arrangement labeling above, so it is advised you check out the pins to which each part of the segment is connected to prior to use.
Segment Pinout
  •  
  • (ii) Before use, check out to confirm which configuration your segment display has as regards being either of Common-Anode or Common-Cathode arrangement.
  •  
  • (iii)Being basically LEDs, always connect up your current limiting resistors

 

 

                           Step 2: Build The Circuit

 

Fritzing Wiring

 

7-Segment Circuit Diagram

 

As illustrated in the schematic diagram above, the LEDs making up the segment-display connect up to the microcontroller board digital pin1 through to pin7 via the current limiting resistors. The dp segment-pin connection is left out for we are not implementing any decimal point display in this project.

Likewise, the two switches connect to p8 and p9 respectively, with the pins’ resistors in the pull-up mode. The former increments the counter whereas the latter does the decrementing.

Power can be sourced to the board either via the USB Softcard; or via connecting an external power supply (between 7 – 12 VDC) to the VIN pin of the microcontroller board.

 

                      Step 3: Build The Source Code

The software program to run the project is as follows:

Segment_code

Let’s try to explore the code in a little more detail:

Working with the segment display might be a bit tasking code-wise for especially a newbie! But nothing to worry much about as the CloudX has really simplified the whole process, thereby abstracting the somewhat associated complex data manipulation from the end user. Here, we will be utilizing the segment library, as already indicated in the code, to ease off the work.

7-Segment Array Setup

Since we are dealing with a digit display:   NumberOfDigit = 1.

The segment pin a through to pin g are interfaced with the microcontroller pin 1 through to pin 7 respectively. Thus:

segment Data Pins

Since the segment common pin is not interfaced with the microcontroller, thus:

Segment Scan Pins

The segment function-call seen in the set-up section of the code takes in as the parameters:

  • (i)   the segment common pin configuration
  • •    CCathode for the common-cathode’s
  • •    CAnode for the common-anode’s
  • (ii) and the rest of the other parameters we have already met in the declaration section.
  •  

Thus:

Segment_setting(CCathode,NumberOfDigit,segmentScanPins,segmentDataPins);

 

 

                          Step 4: Compile The Code

At this stage, the source code is compiled accordingly to get a hex file that is to be loaded into the microcontroller later on.

For further details on how to compile the code into an executable (hex) file, you can refer to this link.

 

                     Step 5: Load In The Hex Code File

Now, it is really time to get our project fully prepared to power up. The already derived hex file is burnt into the microcontroller. 

For further details on how to burn in the code to the microcontroller, you can refer to this link.

 

                        Step 6: Power Up The Project

The project is finally powered on, and should come fully alive as specified in our design.

7-Segment Circuit Simulated

 

 

 

At this juncture we’ve learnt how to play ourselves around an LED display called the 7-Segment Display, let’s still further expand our knowledge on the LED manipulation. In the case to follow, we will be making use of a shift-register IC (integrated) chip control to maneuvre the ON and OFF states of the individual members of an array of LEDs. In effect, this (maneuvering) creates a beautiful display pattern known as LED chaser pattern. So, continue on to the next lesson as we make further attempts at exploring embedded systems design using CloudX.

 

 

--------------------------------------------------------------------------------

Copy the Code

 

#include <CloudX\Segment.h>  //includes the segment library into our work  

#define increase 8 //digital pin 8 to increase Button
#define decrease 9 //digital pin 9 to decrease Button

char i = 0;
char NumberOfDigit = 1;
char segmentDataPins[] = {1, 2, 3, 4, 5, 6, 7, NULL}; //a,b,c,d,e,f,g,dp
char segmentScanPins[] = 0;

setup(){
//setup here

pinMode(decrease, INPUT);
pinMode(increase, INPUT);
Segment_setting(CCathode, NumberOfDigit, segmentScanPins, segmentDataPins);

loop(){
//Program here

//execute this section of code if decrease button is pressed
if(readPin(decrease) is 0)
{
delayMs(110); //removes the possibility of switch bounce
i--; //reduces the i variable by one
}

//execute this section of code if decrease button is pressed
if(readPin(increase) is 0)
{
delayMs(110); //removes the possibility of switch bounce
i++; //increases the i variable by one
}

// Make sure i variable stays in the range of 0 - 9
if(i is 255) i = 9; //if the value inside the i variable is 255, change it to 9
if(i is 10) i = 0; //if the value inside the i variable is 10, change it to 0

Segment_write(i, 1000); //displays current value of i variable on 7 -segment

}
}
 

--------------------------------------------------------------------------------------

Share this with friends