asdf

Dependencies:   NokiaLCD XMIT_IR mbed

Fork of 4180_mP_WirelessPong_revC by Curtis Mulady

Committer:
cmulady
Date:
Thu Oct 04 15:12:58 2012 +0000
Revision:
4:8fdff78c13c8
Parent:
3:8e492eacd346
Child:
5:2e08cc167fff
ir data xmission troublesome;

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 DigitalIn IRLED_rx(p20);
cmulady 1:9ba884d85ac6 28
cmulady 3:8e492eacd346 29 //Global Vars
cmulady 1:9ba884d85ac6 30 char buffer[32];
cmulady 3:8e492eacd346 31 unsigned char irdata_out=0;
cmulady 3:8e492eacd346 32 unsigned char irdata_in=0;
cmulady 1:9ba884d85ac6 33
cmulady 3:8e492eacd346 34 //Function Prototypes
cmulady 1:9ba884d85ac6 35 void BlinkAlive(void const* arguments);
cmulady 1:9ba884d85ac6 36 void UpdateLCD(void const* arguments);
cmulady 3:8e492eacd346 37 void IRStuff(void const* arguments);
cmulady 1:9ba884d85ac6 38
cmulady 1:9ba884d85ac6 39
cmulady 1:9ba884d85ac6 40 int main()
cmulady 1:9ba884d85ac6 41 {
cmulady 0:c8ddcaa575ba 42
cmulady 3:8e492eacd346 43 //LCD init
cmulady 0:c8ddcaa575ba 44 lcd.background(0x000000);
cmulady 1:9ba884d85ac6 45
cmulady 3:8e492eacd346 46 //PWM init
cmulady 3:8e492eacd346 47 IRLED_mod.period(1.0/38000.0); //38kHz Modulation Freq
cmulady 3:8e492eacd346 48 IRLED_mod = 0.5; //pulse width = 50%
cmulady 3:8e492eacd346 49
cmulady 3:8e492eacd346 50 //Serial init
cmulady 3:8e492eacd346 51 device.baud(2400);
cmulady 3:8e492eacd346 52
cmulady 3:8e492eacd346 53 //Thread init
cmulady 1:9ba884d85ac6 54 Thread thread_blinkalive(BlinkAlive);
cmulady 1:9ba884d85ac6 55 Thread thread_updatelcd(UpdateLCD);
cmulady 3:8e492eacd346 56 Thread thread_irstuff(IRStuff);
cmulady 1:9ba884d85ac6 57
cmulady 1:9ba884d85ac6 58
cmulady 1:9ba884d85ac6 59
cmulady 0:c8ddcaa575ba 60 while(1) {
cmulady 1:9ba884d85ac6 61 thread_updatelcd.signal_set(0x1);
cmulady 1:9ba884d85ac6 62 Thread::wait(1000/FPS);
cmulady 1:9ba884d85ac6 63
cmulady 0:c8ddcaa575ba 64 }
cmulady 0:c8ddcaa575ba 65 }
cmulady 1:9ba884d85ac6 66
cmulady 1:9ba884d85ac6 67 void UpdateLCD(void const* arguments)
cmulady 1:9ba884d85ac6 68 {
cmulady 1:9ba884d85ac6 69 while(true) {
cmulady 1:9ba884d85ac6 70 led2 = 1;
cmulady 1:9ba884d85ac6 71 lcd.locate(0,1);
cmulady 1:9ba884d85ac6 72 lcd.printf("Debug:");
cmulady 1:9ba884d85ac6 73
cmulady 1:9ba884d85ac6 74 lcd.locate(0,3);
cmulady 1:9ba884d85ac6 75 time_t seconds = time(NULL);
cmulady 1:9ba884d85ac6 76 strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
cmulady 1:9ba884d85ac6 77 lcd.printf("%s", buffer);
cmulady 1:9ba884d85ac6 78
cmulady 3:8e492eacd346 79 lcd.locate(0,4);
cmulady 3:8e492eacd346 80 lcd.printf("IR_OUT=0x%X", irdata_out);
cmulady 3:8e492eacd346 81 lcd.locate(0,5);
cmulady 3:8e492eacd346 82 lcd.printf("IR_IN= 0x%X", irdata_in);
cmulady 3:8e492eacd346 83
cmulady 3:8e492eacd346 84
cmulady 3:8e492eacd346 85
cmulady 1:9ba884d85ac6 86 //End - Sleep thread
cmulady 1:9ba884d85ac6 87 led2 = 0;
cmulady 1:9ba884d85ac6 88 Thread::signal_wait(0x1);
cmulady 1:9ba884d85ac6 89 }
cmulady 1:9ba884d85ac6 90 }
cmulady 1:9ba884d85ac6 91
cmulady 3:8e492eacd346 92 void IRStuff(void const* arguments)
cmulady 3:8e492eacd346 93 {
cmulady 3:8e492eacd346 94 while(true) {
cmulady 3:8e492eacd346 95 device.putc(irdata_out);
cmulady 3:8e492eacd346 96 if(device.readable()) {
cmulady 3:8e492eacd346 97 irdata_in = device.getc();
cmulady 3:8e492eacd346 98 }
cmulady 4:8fdff78c13c8 99 Thread::wait(300);
cmulady 3:8e492eacd346 100 }
cmulady 4:8fdff78c13c8 101
cmulady 3:8e492eacd346 102 }
cmulady 3:8e492eacd346 103
cmulady 1:9ba884d85ac6 104 void BlinkAlive(void const* arguments)
cmulady 1:9ba884d85ac6 105 {
cmulady 1:9ba884d85ac6 106 while(true) {
cmulady 1:9ba884d85ac6 107 led1 = !led1;
cmulady 3:8e492eacd346 108 irdata_out++;
cmulady 3:8e492eacd346 109 Thread::wait(1000);
cmulady 1:9ba884d85ac6 110 }
cmulady 1:9ba884d85ac6 111 }