TOMB / Mbed 2 deprecated 0508_Lab1

Dependencies:   mbed

main.cpp

Committer:
Gennanio
Date:
2015-10-15
Revision:
0:de79186306b0

File content as of revision 0:de79186306b0:

// Lab 1
// 15/10/2015
#include "mbed.h"

DigitalOut l1(D10),l2(D9),l3(D8),l4(D7),l5(D6),l6(D5),l7(D4),l8(D3);
DigitalIn x(D11),y(D12),z(D13);

void ledOFF();
void State1();
void State2();
void State3();
void State4();
void State5();

int main() 
{
    while(1) 
    {
        if(!x&&!y&&z) //001
        {
            ledOFF();
            State1();
        }
        else
        {
            if(!x&&y&&!z) //010
            {
                ledOFF();
                State2();
            }
            else
            {
                if(x&&!y&&!z) //100
                {
                    ledOFF();
                    State3();
                }
                else
                {
                    if(!x&&y&&z) //011
                    {
                        ledOFF();
                        State4();
                    }
                    else
                    {
                        if(x&&y&&z) //111
                        {
                            ledOFF();
                            State5();
                        }
                        else
                        {
                            ledOFF();
                        }
                    }
                }    
            }
        }
        wait_ms(200);
    }
}

void ledOFF()
{
    l1=0; l2=0; l3=0; l4=0; l5=0; l6=0; l7=0; l8=0;     
}
void State1()
{
    do
    {
        l1=1; wait_ms(100);
        l2=1; wait_ms(100);
        l3=1; wait_ms(100);
        l4=1; wait_ms(100);
        l5=1; wait_ms(100);
        l6=1; wait_ms(100);
        l7=1; wait_ms(100);
        l8=1; wait_ms(100);
        
        l1=0; wait_ms(100);
        l2=0; wait_ms(100);
        l3=0; wait_ms(100);
        l4=0; wait_ms(100);
        l5=0; wait_ms(100);
        l6=0; wait_ms(100);
        l7=0; wait_ms(100);
        l8=0; wait_ms(100);
        ledOFF();
    }while(!x&&!y&&z);
}
void State2()
{
    do
    {
        l8=1; wait_ms(100);
        l7=1; wait_ms(100);
        l6=1; wait_ms(100);
        l5=1; wait_ms(100);
        l4=1; wait_ms(100);
        l3=1; wait_ms(100);
        l2=1; wait_ms(100);
        l1=1; wait_ms(100);
        
        l8=0; wait_ms(100);
        l7=0; wait_ms(100);
        l6=0; wait_ms(100);
        l5=0; wait_ms(100);
        l4=0; wait_ms(100);
        l3=0; wait_ms(100);
        l2=0; wait_ms(100);
        l1=0; wait_ms(100);
        ledOFF();
    }while(!x&&y&&!z);
}
void State3()
{
    do
    {
        l1=1; l3=1; l5=1; l7=1; wait_ms(300);
        l1=0; l3=0; l5=0; l7=0; 
        l2=1; l4=1; l6=1; l8=1; wait_ms(300);
        l2=0; l4=0; l6=0; l8=0;
        ledOFF();
    }while(x&&!y&&!z);
}
void State4()
{
    do
    {
        l1=1; l8=1; wait_ms(100);
        l2=1; l7=1; wait_ms(100);
        l3=1; l6=1; wait_ms(100);
        l4=1; l5=1; wait_ms(100);
        
        l4=0; l5=0; wait_ms(100);
        l3=0; l6=0; wait_ms(100);
        l2=0; l7=0; wait_ms(100);
        l1=0; l8=0; wait_ms(100);
        ledOFF();
    }while(!x&&y&&z);
}
void State5()
{
    do
    {
        l1=1; l5=1; wait_ms(300); //0001
        l1=0; l5=0;
        l2=1; l6=1; wait_ms(300); //0010
        l1=1; l5=1; wait_ms(300); //0011
        l1=0; l5=0; l2=0; l6=0;
        
        l3=1; l7=1; wait_ms(300); //0100
        
        l1=1; l5=1; wait_ms(300); //0101
        l1=0; l5=0;
        l2=1; l6=1; wait_ms(300); //0110
        l1=1; l5=1; wait_ms(300); //0111
        l1=0; l5=0; l2=0; l6=0; l3=0; l7=0;
        
        l4=1; l8=1; wait_ms(300); //1000
        
        l1=1; l5=1; wait_ms(300); //1001
        l1=0; l5=0;
        l2=1; l6=1; wait_ms(300); //1010
        l1=1; l5=1; wait_ms(300); //1011
        l1=0; l5=0; l2=0; l6=0;
        l3=1; l7=1; wait_ms(300); //1100
        l1=1; l5=1; wait_ms(300); //1101
        l1=0; l5=0;
        l2=1; l6=1; wait_ms(300); //1110
        l1=1; l5=1; wait_ms(300); //1111
        ledOFF();
    }while(x&&y&&z);
}