Tedd OKANO / Mbed 2 deprecated mbeduino_LED_Cube444_test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LED_Cube444_test.cpp Source File

LED_Cube444_test.cpp

00001 //  mbeduino test code (with 4x4x4 LED Cube shield)
00002 //
00003 //      mbeduino              = http://mbed.org/users/okini3939/notebook/mbeduino/  (Japanese)
00004 //      4x4x4 LED Cube shield = http://www.galileo-7.com/?pid=20015630  (Japanese)
00005 //
00006 //  This is just simple code to check the mbeduino and the 4x4x4 LED Cube shield operation
00007 //  It turns-on each indivisual LEDs one by one. 
00008 //  
00009 
00010 #include "mbed.h"
00011 #include "mbeduino_shield.h"
00012 
00013 #define     CUBE_SIZE       4                       //  n of nodes on one edge
00014 #define     SR_BIT_LENGTH   (CUBE_SIZE * CUBE_SIZE) //  n of bits on one layer
00015 
00016 typedef     unsigned short  U16;    //  bit length should be same or more than SR_BIT_LENGTH
00017 
00018 #define     SR_DATA_OUT     ARD_D2  //  data line to the shiftregister
00019 #define     SR_CLCK_OUT     ARD_D3  //  clock line to the shiftregister
00020 #define     CATHODE0        ARD_D11 //  cathode control line for bottom layer
00021 #define     CATHODE1        ARD_D10 //  cathode control line for 2nd layer from bottom
00022 #define     CATHODE2        ARD_D9  //  cathode control line for 3nd layer from bottom
00023 #define     CATHODE3        ARD_D8  //  cathode control line for top layer
00024 
00025 DigitalOut  sr_data(SR_DATA_OUT);
00026 DigitalOut  sr_clk(SR_CLCK_OUT);
00027 BusOut      cathode( CATHODE0, CATHODE1, CATHODE2, CATHODE3 );
00028 
00029 //U16         main_buffer[ CUBE_SIZE ]    = { 0, 0, 0, 0 };
00030 
00031 void set_serialregister( U16 v );
00032 
00033 int main() {
00034     cathode = 0x0;
00035 
00036     while (1) {
00037         for ( int c = 0; c < CUBE_SIZE; c++ ) {
00038             for ( int i = 0; i < SR_BIT_LENGTH; i++ ) {
00039                 set_serialregister( 0x0001 << i );
00040                 
00041                 cathode = 0x1 << c;
00042                 wait( 0.05 );
00043                 cathode = 0x0;
00044             }
00045         }
00046     }
00047 }
00048 
00049 void set_serialregister( U16 v ) {
00050     for ( int i = 0; i < SR_BIT_LENGTH; i++ ) {
00051         sr_data = ((v >> i) & 0x1);
00052         sr_clk  = 0;
00053         sr_clk  = 1;
00054     }
00055 }
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073