asdf

Dependencies:   NokiaLCD XMIT_IR mbed

Fork of 4180_mP_WirelessPong_revC by Curtis Mulady

main.cpp

Committer:
cmulady
Date:
2012-10-04
Revision:
4:8fdff78c13c8
Parent:
3:8e492eacd346
Child:
5:2e08cc167fff

File content as of revision 4:8fdff78c13c8:

#include "mbed.h"
#include "rtos.h"
#include "NokiaLCD.h"
#include "XMIT_IR.h"

#define FPS 5

/****************************************
|=======================================|
|MBED Connections:                      |
|   -p5 : DIO on Sparkfun Nokia LCD     |
|   -p7 : CLK on Sparkfun Nokia LCD     |
|   -p8 : CS  on Sparkfun Nokia LCD     |
|   -p9 : RST on Sparkfun Nokia LCD     |
|   -p22: GND on Sparkfun IR Xmtr       |
|=======================================|
****************************************/

//Pin Setup
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type
Serial device(p28, p27);  // tx, rx
PwmOut IRLED_mod(p22);
DigitalIn IRLED_rx(p20);

//Global Vars
char buffer[32];
unsigned char irdata_out=0;
unsigned char irdata_in=0;

//Function Prototypes
void BlinkAlive(void const* arguments);
void UpdateLCD(void const* arguments);
void IRStuff(void const* arguments);


int main()
{

    //LCD init
    lcd.background(0x000000);

    //PWM init
    IRLED_mod.period(1.0/38000.0);  //38kHz Modulation Freq
    IRLED_mod = 0.5;                //pulse width = 50%

    //Serial init
    device.baud(2400);

    //Thread init
    Thread thread_blinkalive(BlinkAlive);
    Thread thread_updatelcd(UpdateLCD);
    Thread thread_irstuff(IRStuff);



    while(1) {
        thread_updatelcd.signal_set(0x1);
        Thread::wait(1000/FPS);

    }
}

void UpdateLCD(void const* arguments)
{
    while(true) {
        led2 = 1;
        lcd.locate(0,1);
        lcd.printf("Debug:");

        lcd.locate(0,3);
        time_t seconds = time(NULL);
        strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
        lcd.printf("%s", buffer);

        lcd.locate(0,4);
        lcd.printf("IR_OUT=0x%X", irdata_out);
        lcd.locate(0,5);
        lcd.printf("IR_IN= 0x%X", irdata_in);



        //End - Sleep thread
        led2 = 0;
        Thread::signal_wait(0x1);
    }
}

void IRStuff(void const* arguments)
{
    while(true) {
        device.putc(irdata_out);
        if(device.readable()) {
            irdata_in = device.getc();
        }
        Thread::wait(300);
    }

}

void BlinkAlive(void const* arguments)
{
    while(true) {
        led1 = !led1;
        irdata_out++;
        Thread::wait(1000);
    }
}