asdf

Dependencies:   NokiaLCD XMIT_IR mbed

Fork of 4180_mP_WirelessPong_revC by Curtis Mulady

Committer:
cmulady
Date:
Thu Oct 04 14:54:59 2012 +0000
Revision:
3:8e492eacd346
Parent:
1:9ba884d85ac6
Child:
4:8fdff78c13c8
got some ir stuff working. issues with serial data transmission.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cmulady 0:c8ddcaa575ba 1 #include "mbed.h"
cmulady 0:c8ddcaa575ba 2 #include "rtos.h"
cmulady 0:c8ddcaa575ba 3 #include "NokiaLCD.h"
cmulady 1:9ba884d85ac6 4 #include "XMIT_IR.h"
cmulady 0:c8ddcaa575ba 5
cmulady 1:9ba884d85ac6 6 #define FPS 5
cmulady 1:9ba884d85ac6 7
cmulady 3:8e492eacd346 8 /****************************************
cmulady 3:8e492eacd346 9 |=======================================|
cmulady 3:8e492eacd346 10 |MBED Connections: |
cmulady 3:8e492eacd346 11 | -p5 : DIO on Sparkfun Nokia LCD |
cmulady 3:8e492eacd346 12 | -p7 : CLK on Sparkfun Nokia LCD |
cmulady 3:8e492eacd346 13 | -p8 : CS on Sparkfun Nokia LCD |
cmulady 3:8e492eacd346 14 | -p9 : RST on Sparkfun Nokia LCD |
cmulady 3:8e492eacd346 15 | -p22: GND on Sparkfun IR Xmtr |
cmulady 3:8e492eacd346 16 |=======================================|
cmulady 3:8e492eacd346 17 ****************************************/
cmulady 1:9ba884d85ac6 18
cmulady 3:8e492eacd346 19 //Pin Setup
cmulady 1:9ba884d85ac6 20 DigitalOut led1(LED1);
cmulady 1:9ba884d85ac6 21 DigitalOut led2(LED2);
cmulady 3:8e492eacd346 22 DigitalOut led3(LED3);
cmulady 3:8e492eacd346 23 DigitalOut led4(LED4);
cmulady 0:c8ddcaa575ba 24 NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type
cmulady 3:8e492eacd346 25 Serial device(p28, p27); // tx, rx
cmulady 3:8e492eacd346 26 PwmOut IRLED_mod(p22);
cmulady 3:8e492eacd346 27 DigitalOut IRLED_ctrl(p22);
cmulady 3:8e492eacd346 28 DigitalIn IRLED_rx(p20);
cmulady 1:9ba884d85ac6 29
cmulady 3:8e492eacd346 30 //Global Vars
cmulady 1:9ba884d85ac6 31 char buffer[32];
cmulady 3:8e492eacd346 32 unsigned char irdata_out=0;
cmulady 3:8e492eacd346 33 unsigned char irdata_in=0;
cmulady 1:9ba884d85ac6 34
cmulady 3:8e492eacd346 35 //Function Prototypes
cmulady 1:9ba884d85ac6 36 void BlinkAlive(void const* arguments);
cmulady 1:9ba884d85ac6 37 void UpdateLCD(void const* arguments);
cmulady 3:8e492eacd346 38 void IRStuff(void const* arguments);
cmulady 1:9ba884d85ac6 39
cmulady 1:9ba884d85ac6 40
cmulady 1:9ba884d85ac6 41 int main()
cmulady 1:9ba884d85ac6 42 {
cmulady 0:c8ddcaa575ba 43
cmulady 3:8e492eacd346 44 //LCD init
cmulady 0:c8ddcaa575ba 45 lcd.background(0x000000);
cmulady 1:9ba884d85ac6 46
cmulady 3:8e492eacd346 47 //PWM init
cmulady 3:8e492eacd346 48 IRLED_mod.period(1.0/38000.0); //38kHz Modulation Freq
cmulady 3:8e492eacd346 49 IRLED_mod = 0.5; //pulse width = 50%
cmulady 3:8e492eacd346 50
cmulady 3:8e492eacd346 51 //Serial init
cmulady 3:8e492eacd346 52 device.baud(2400);
cmulady 3:8e492eacd346 53
cmulady 3:8e492eacd346 54 //Thread init
cmulady 1:9ba884d85ac6 55 Thread thread_blinkalive(BlinkAlive);
cmulady 1:9ba884d85ac6 56 Thread thread_updatelcd(UpdateLCD);
cmulady 3:8e492eacd346 57 Thread thread_irstuff(IRStuff);
cmulady 1:9ba884d85ac6 58
cmulady 1:9ba884d85ac6 59
cmulady 1:9ba884d85ac6 60
cmulady 0:c8ddcaa575ba 61 while(1) {
cmulady 1:9ba884d85ac6 62 thread_updatelcd.signal_set(0x1);
cmulady 1:9ba884d85ac6 63 Thread::wait(1000/FPS);
cmulady 1:9ba884d85ac6 64
cmulady 0:c8ddcaa575ba 65 }
cmulady 0:c8ddcaa575ba 66 }
cmulady 1:9ba884d85ac6 67
cmulady 1:9ba884d85ac6 68 void UpdateLCD(void const* arguments)
cmulady 1:9ba884d85ac6 69 {
cmulady 1:9ba884d85ac6 70 while(true) {
cmulady 1:9ba884d85ac6 71 led2 = 1;
cmulady 1:9ba884d85ac6 72 lcd.locate(0,1);
cmulady 1:9ba884d85ac6 73 lcd.printf("Debug:");
cmulady 1:9ba884d85ac6 74
cmulady 1:9ba884d85ac6 75 lcd.locate(0,3);
cmulady 1:9ba884d85ac6 76 time_t seconds = time(NULL);
cmulady 1:9ba884d85ac6 77 strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
cmulady 1:9ba884d85ac6 78 lcd.printf("%s", buffer);
cmulady 1:9ba884d85ac6 79
cmulady 3:8e492eacd346 80 lcd.locate(0,4);
cmulady 3:8e492eacd346 81 lcd.printf("IR_OUT=0x%X", irdata_out);
cmulady 3:8e492eacd346 82 lcd.locate(0,5);
cmulady 3:8e492eacd346 83 lcd.printf("IR_IN= 0x%X", irdata_in);
cmulady 3:8e492eacd346 84
cmulady 3:8e492eacd346 85
cmulady 3:8e492eacd346 86
cmulady 1:9ba884d85ac6 87 //End - Sleep thread
cmulady 1:9ba884d85ac6 88 led2 = 0;
cmulady 1:9ba884d85ac6 89 Thread::signal_wait(0x1);
cmulady 1:9ba884d85ac6 90 }
cmulady 1:9ba884d85ac6 91 }
cmulady 1:9ba884d85ac6 92
cmulady 3:8e492eacd346 93 void IRStuff(void const* arguments)
cmulady 3:8e492eacd346 94 {
cmulady 3:8e492eacd346 95 while(true) {
cmulady 3:8e492eacd346 96 device.putc(irdata_out);
cmulady 3:8e492eacd346 97 if(device.readable()) {
cmulady 3:8e492eacd346 98 irdata_in = device.getc();
cmulady 3:8e492eacd346 99 }
cmulady 3:8e492eacd346 100 }
cmulady 3:8e492eacd346 101 }
cmulady 3:8e492eacd346 102
cmulady 1:9ba884d85ac6 103 void BlinkAlive(void const* arguments)
cmulady 1:9ba884d85ac6 104 {
cmulady 1:9ba884d85ac6 105 while(true) {
cmulady 1:9ba884d85ac6 106 led1 = !led1;
cmulady 3:8e492eacd346 107 IRLED_ctrl = led1;
cmulady 3:8e492eacd346 108 irdata_out++;
cmulady 3:8e492eacd346 109 Thread::wait(1000);
cmulady 1:9ba884d85ac6 110 }
cmulady 1:9ba884d85ac6 111 }