This is a driver for a project I made in school. It involves a Raspberry Pi connected to the MBED, which in turn is connected to a Ledcube. The MBED delivers data for the leds to the Ledcube continuously at a 100 Hz rate, using SPI. This data is read from an internal buffer. For animations, the Raspberry Pi just sends data when the current "image" has to change, using I2C.

Dependencies:   mbed mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "I2CDriver.h"
00003 #include "SPIDriver.h"
00004 #include "LedCube.h"
00005 #include "rtos.h"
00006 
00007 const int FRAMES = 700;
00008 const int SPIFREQ = 1000000; //frequency of SPI interface
00009 const char ADDRESS = 0x60; //address van I2C interface
00010 unsigned char buffer[512];
00011 Mutex valuesmutex;
00012 
00013 LedCube* ledcube = new LedCube();
00014 SPIDriver* spidriver = new SPIDriver(p5, NC, p7, p8, p11, SPIFREQ);
00015 I2CDriver* i2cdriver = new I2CDriver(p28, p27, ADDRESS);
00016 DigitalOut blank(p9);
00017 
00018 void streamThread(void const* args);
00019 void inputThread(void const* args);
00020 
00021 int main()
00022 {
00023     /* while(true){
00024          spidriver->sendLayer(ledcube);
00025          wait(0.5);
00026      }  */
00027     /*  blank = 1;
00028       wait_ms(1);*/
00029     blank = 0;
00030 
00031     for(int i = 0; i < 512; i++) buffer[i] = 1;
00032 
00033     ledcube->setData(buffer);
00034 
00035     /* while(1){}*/
00036 
00037     /* while(true) {
00038           char ledvalue = ledcube->getNextValue();
00039           printf("%d ", ledvalue);
00040           spidriver->write(ledvalue);
00041           wait(0.2);
00042       }*/
00043 
00044     //  spidriver->testPhase(FRAMES);
00045 
00046     /*  printf("Initiating stream from following matrices\n\r");
00047       ledcube->printAll();
00048       printf("Streaming...\n\r");*/
00049     /*   spidriver->sendLayer(ledcube);
00050        wait(0.00125);    //voor 100 Hz
00051        spidriver->pulseLatch();*/
00052      
00053    /* while(true) {
00054         spidriver->sendFrame(ledcube);
00055     }*/
00056     
00057     Thread thread1(streamThread);
00058     Thread thread2(inputThread);
00059     while(true){}
00060     
00061 }//end main
00062 
00063 void streamThread(void const* args)
00064 {
00065     while(true) {
00066         valuesmutex.lock();
00067         spidriver->sendFrame(ledcube);
00068         valuesmutex.unlock();
00069     }
00070 }
00071 
00072 void inputThread(void const* args)
00073 {
00074     while(true) {
00075         valuesmutex.lock();
00076         i2cdriver->pollForInput(ledcube);
00077         valuesmutex.unlock();
00078     }
00079 }