miniProject-Wireless Pong

Committer:
cmulady
Date:
Thu Oct 04 18:33:25 2012 +0000
Revision:
5:2e08cc167fff
Parent:
4:8fdff78c13c8
Child:
6:5563f0026858
Now IR stuff works. Next step is to start writing a library for it.

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