Hello kevin
Dependencies: 4DGL-uLCD-SE MutexLocker SDFileSystem mbed-rtos mbed wave_player
Fork of uLCD144G2_demo by
main.cpp@9:ce140873ae0a, 2015-10-05 (annotated)
- Committer:
- rproctor6
- Date:
- Mon Oct 05 18:12:25 2015 +0000
- Revision:
- 9:ce140873ae0a
- Parent:
- 8:31e63caf37e2
Kevin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 8:31e63caf37e2 | 1 | // uLCD-144-G2 demo program for uLCD-4GL LCD driver library |
4180_1 | 0:cfcf73272647 | 2 | // |
4180_1 | 0:cfcf73272647 | 3 | #include "mbed.h" |
rproctor6 | 9:ce140873ae0a | 4 | #include "Speaker.h" |
4180_1 | 2:75727e89a717 | 5 | #include "uLCD_4DGL.h" |
rproctor6 | 9:ce140873ae0a | 6 | #include "rtos.h" |
rproctor6 | 9:ce140873ae0a | 7 | #include "SDFileSystem.h" |
rproctor6 | 9:ce140873ae0a | 8 | #include "wave_player.h" |
rproctor6 | 9:ce140873ae0a | 9 | #include "mutexlocker.h" |
rproctor6 | 9:ce140873ae0a | 10 | |
rproctor6 | 9:ce140873ae0a | 11 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
rproctor6 | 9:ce140873ae0a | 12 | |
rproctor6 | 9:ce140873ae0a | 13 | AnalogOut DACout(p18); |
rproctor6 | 9:ce140873ae0a | 14 | |
rproctor6 | 9:ce140873ae0a | 15 | wave_player waver(&DACout); |
rproctor6 | 9:ce140873ae0a | 16 | |
rproctor6 | 9:ce140873ae0a | 17 | |
rproctor6 | 9:ce140873ae0a | 18 | Mutex myMutex; |
4180_1 | 0:cfcf73272647 | 19 | |
rproctor6 | 9:ce140873ae0a | 20 | uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; |
rproctor6 | 9:ce140873ae0a | 21 | DigitalOut latch(p15); |
rproctor6 | 9:ce140873ae0a | 22 | DigitalOut enable(p16); |
rproctor6 | 9:ce140873ae0a | 23 | |
rproctor6 | 9:ce140873ae0a | 24 | //Cycles through different colors on RGB LED |
rproctor6 | 9:ce140873ae0a | 25 | SPI spi(p11, p12, p13); |
rproctor6 | 9:ce140873ae0a | 26 | |
rproctor6 | 9:ce140873ae0a | 27 | int red; |
rproctor6 | 9:ce140873ae0a | 28 | int blue; |
rproctor6 | 9:ce140873ae0a | 29 | int green; |
rproctor6 | 9:ce140873ae0a | 30 | |
rproctor6 | 9:ce140873ae0a | 31 | void Sound(void const *args) { |
rproctor6 | 9:ce140873ae0a | 32 | FILE *wave_file; |
rproctor6 | 9:ce140873ae0a | 33 | printf("\n\n\nHello, wave world!\n"); |
rproctor6 | 9:ce140873ae0a | 34 | wave_file=fopen("/sd/sample.wav","r"); |
rproctor6 | 9:ce140873ae0a | 35 | waver.play(wave_file); |
rproctor6 | 9:ce140873ae0a | 36 | fclose(wave_file); |
rproctor6 | 9:ce140873ae0a | 37 | } |
4180_1 | 0:cfcf73272647 | 38 | |
rproctor6 | 9:ce140873ae0a | 39 | void RGB_LED(int red, int green, int blue) { |
rproctor6 | 9:ce140873ae0a | 40 | unsigned int low_color=0; |
rproctor6 | 9:ce140873ae0a | 41 | unsigned int high_color=0; |
rproctor6 | 9:ce140873ae0a | 42 | high_color=(blue<<4)|((red&0x3C0)>>6); |
rproctor6 | 9:ce140873ae0a | 43 | low_color=(((red&0x3F)<<10)|(green)); |
rproctor6 | 9:ce140873ae0a | 44 | spi.write(high_color); |
rproctor6 | 9:ce140873ae0a | 45 | spi.write(low_color); |
rproctor6 | 9:ce140873ae0a | 46 | latch=1; |
rproctor6 | 9:ce140873ae0a | 47 | latch=0; |
rproctor6 | 9:ce140873ae0a | 48 | } |
rproctor6 | 9:ce140873ae0a | 49 | |
rproctor6 | 9:ce140873ae0a | 50 | void LightControl(void const *args){ |
rproctor6 | 9:ce140873ae0a | 51 | |
rproctor6 | 9:ce140873ae0a | 52 | int red=2; |
rproctor6 | 9:ce140873ae0a | 53 | int green=2; |
rproctor6 | 9:ce140873ae0a | 54 | int blue=2; |
rproctor6 | 9:ce140873ae0a | 55 | spi.format(16,0); |
rproctor6 | 9:ce140873ae0a | 56 | spi.frequency(500000); |
rproctor6 | 9:ce140873ae0a | 57 | enable=0; |
rproctor6 | 9:ce140873ae0a | 58 | latch=0; |
rproctor6 | 9:ce140873ae0a | 59 | wait(2); |
rproctor6 | 9:ce140873ae0a | 60 | while(red < 90) { |
rproctor6 | 9:ce140873ae0a | 61 | RGB_LED(red++, green++, blue++); |
rproctor6 | 9:ce140873ae0a | 62 | wait(10); |
rproctor6 | 9:ce140873ae0a | 63 | } |
rproctor6 | 9:ce140873ae0a | 64 | |
rproctor6 | 9:ce140873ae0a | 65 | |
rproctor6 | 9:ce140873ae0a | 66 | Thread::wait(1000); |
rproctor6 | 9:ce140873ae0a | 67 | |
rproctor6 | 9:ce140873ae0a | 68 | |
rproctor6 | 9:ce140873ae0a | 69 | } |
rproctor6 | 9:ce140873ae0a | 70 | |
rproctor6 | 9:ce140873ae0a | 71 | void LCD1(void const *args) { |
rproctor6 | 9:ce140873ae0a | 72 | myMutex.lock(); |
rproctor6 | 9:ce140873ae0a | 73 | while(true){ |
4180_1 | 3:454d1f4c8fd7 | 74 | uLCD.text_width(4); //4X size text |
4180_1 | 3:454d1f4c8fd7 | 75 | uLCD.text_height(4); |
rproctor6 | 9:ce140873ae0a | 76 | uLCD.color(GREEN); |
4180_1 | 3:454d1f4c8fd7 | 77 | for (int i=10; i>=0; --i) { |
4180_1 | 3:454d1f4c8fd7 | 78 | uLCD.locate(1,2); |
4180_1 | 3:454d1f4c8fd7 | 79 | uLCD.printf("%2D",i); |
4180_1 | 3:454d1f4c8fd7 | 80 | wait(.5); |
4180_1 | 3:454d1f4c8fd7 | 81 | } |
4180_1 | 3:454d1f4c8fd7 | 82 | uLCD.cls(); |
rproctor6 | 9:ce140873ae0a | 83 | Thread::wait(1000); |
rproctor6 | 9:ce140873ae0a | 84 | |
rproctor6 | 9:ce140873ae0a | 85 | |
rproctor6 | 9:ce140873ae0a | 86 | |
rproctor6 | 9:ce140873ae0a | 87 | myMutex.unlock(); |
4180_1 | 7:7bd7397ab89f | 88 | } |
rproctor6 | 9:ce140873ae0a | 89 | |
rproctor6 | 9:ce140873ae0a | 90 | } |
4180_1 | 7:7bd7397ab89f | 91 | |
rproctor6 | 9:ce140873ae0a | 92 | void LCD2(void const *args) { |
rproctor6 | 9:ce140873ae0a | 93 | myMutex.lock(); |
rproctor6 | 9:ce140873ae0a | 94 | while(true){ |
rproctor6 | 9:ce140873ae0a | 95 | uLCD.text_width(3); //4X size text |
rproctor6 | 9:ce140873ae0a | 96 | uLCD.text_height(3); |
rproctor6 | 9:ce140873ae0a | 97 | uLCD.color(RED); |
rproctor6 | 9:ce140873ae0a | 98 | for (int i=10; i>=0; --i) { |
rproctor6 | 9:ce140873ae0a | 99 | uLCD.locate(1,2); |
rproctor6 | 9:ce140873ae0a | 100 | uLCD.printf("%2D",i); |
rproctor6 | 9:ce140873ae0a | 101 | wait(.5); |
4180_1 | 4:25a266a74a4c | 102 | } |
rproctor6 | 9:ce140873ae0a | 103 | myMutex.unlock(); |
rproctor6 | 9:ce140873ae0a | 104 | //uLCD.cls(); |
rproctor6 | 9:ce140873ae0a | 105 | Thread::wait(1000);} |
rproctor6 | 9:ce140873ae0a | 106 | |
rproctor6 | 9:ce140873ae0a | 107 | } |
rproctor6 | 9:ce140873ae0a | 108 | |
rproctor6 | 9:ce140873ae0a | 109 | |
rproctor6 | 9:ce140873ae0a | 110 | |
rproctor6 | 9:ce140873ae0a | 111 | |
rproctor6 | 9:ce140873ae0a | 112 | int main() |
rproctor6 | 9:ce140873ae0a | 113 | { |
rproctor6 | 9:ce140873ae0a | 114 | Thread thread1(Sound); |
rproctor6 | 9:ce140873ae0a | 115 | Thread thread2(LightControl); |
rproctor6 | 9:ce140873ae0a | 116 | Thread thread3(LCD1); |
rproctor6 | 9:ce140873ae0a | 117 | Thread thread4(LCD2); |
rproctor6 | 9:ce140873ae0a | 118 | |
rproctor6 | 9:ce140873ae0a | 119 | //LightControl(); |
rproctor6 | 9:ce140873ae0a | 120 | //Thread thread1(Sound); |
rproctor6 | 9:ce140873ae0a | 121 | //Thread thread2(Light); |
rproctor6 | 9:ce140873ae0a | 122 | //Thread thread3(LCD1); |
rproctor6 | 9:ce140873ae0a | 123 | //Thread thread4(LCD2); |
rproctor6 | 9:ce140873ae0a | 124 | while(true){ |
rproctor6 | 9:ce140873ae0a | 125 | Thread::wait(100); |
4180_1 | 5:a1ef40ff0f78 | 126 | } |
4180_1 | 6:f752accd632c | 127 | } |
4180_1 | 7:7bd7397ab89f | 128 | |
4180_1 | 7:7bd7397ab89f | 129 | |
4180_1 | 8:31e63caf37e2 | 130 |