TaChing Yu / Mbed 2 deprecated 4_7SgementLED_74HC595

Dependencies:   mbed

main.cpp

Committer:
yu10078999
Date:
2016-09-04
Revision:
1:5002e9577641
Parent:
0:b7855d83d15b

File content as of revision 1:5002e9577641:

#include "mbed.h"

DigitalOut datapin(D8);    
DigitalOut latchpin(D9);   
DigitalOut clockpin(D10);
DigitalOut ww(D11);
DigitalOut xx(D12);
DigitalOut yy(D13);
DigitalOut zz(D14);

const int state[10][8]= {
  { 0, 1, 1, 1, 1, 1, 1}, // 0
  { 0, 0, 0, 0, 1, 1, 0}, // 1
  { 1, 0, 1, 1, 0, 1, 1}, // 2
  { 1, 0, 0, 1, 1, 1, 1}, // 3
  { 1, 1, 0, 0, 1, 1, 0}, // 4
  { 1, 1, 0, 1, 1, 0, 1}, // 5
  { 1, 1, 1, 1, 1, 0, 0}, // 6
  { 0, 0, 0, 0, 1, 1, 1}, // 7
  { 1, 1, 1, 1, 1, 1, 1}, // 8
  { 1, 1, 0, 0, 1, 1, 1}  // 9
};
void seg1(int num)
{
    ww=1;
    xx=1;
    yy=1;
    zz=1;
    latchpin=0;
    for(int i=0;i<=7;i++)
    {
        datapin=state[num][i];
        clockpin=1;
        clockpin=0;
    }
    latchpin=1;
    ww=0;
}
void seg2(int num)
{
    ww=1;
    xx=1;
    yy=1;
    zz=1;
    latchpin=0;
    for(int i=0;i<=7;i++)
    {
        datapin=state[num][i];
        clockpin=1;
        clockpin=0;
    }
    latchpin=1;
    xx=0;
}
void seg3(int num)
{
    ww=1;
    xx=1;
    yy=1;
    zz=1;
    latchpin=0;
    for(int i=0;i<=7;i++)
    {
        datapin=state[num][i];
        clockpin=1;
        clockpin=0;
    }
    latchpin=1;
    yy=0;
}
void seg4(int num)
{
    ww=1;
    xx=1;
    yy=1;
    zz=1;
    latchpin=0;
    for(int i=0;i<=7;i++)
    {
        datapin=state[num][i];
        clockpin=1;
        clockpin=0;
    }
    latchpin=1;
    zz=0;
}
int main() 
{
    int round=0,round2=0,round3=0,round4=0,r=0;;
    while(1) 
    {   
        seg1(round);
        r++;
        if (r>=30)
        {
            round++;
            r=0;
        }
        wait_ms(5);
        seg2(round2);
        wait_ms(5);
        seg3(round3);
        wait_ms(5);
        seg4(round4);
        wait_ms(5);
        if(round == 10)
        {
            round=0;round2++;
            if(round2 == 10)
            {
                round2=0;round3++;
                if(round3 == 10)
                {
                    round3=0;
                    round4++;
                    if(round4 == 10)
                    {
                        round4=0;
                    }
                }
            }
        }
    }
}