![](/media/cache/profiles/9ae782e31c7b7d4fd0e7dbde03909519.jpg.50x50_q85.jpg)
testing
Dependencies: C12832_lcd LCD_fonts LM75B MMA7660 mbed-rtos mbed
main.cpp@0:0a2678204e37, 2014-11-02 (annotated)
- Committer:
- embeddednerd
- Date:
- Sun Nov 02 20:41:59 2014 +0000
- Revision:
- 0:0a2678204e37
testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddednerd | 0:0a2678204e37 | 1 | #include "mbed.h" |
embeddednerd | 0:0a2678204e37 | 2 | #include "rtos.h" |
embeddednerd | 0:0a2678204e37 | 3 | #include "C12832_lcd.h" |
embeddednerd | 0:0a2678204e37 | 4 | #include "Arial_9.h" |
embeddednerd | 0:0a2678204e37 | 5 | #include "Small_7.h" |
embeddednerd | 0:0a2678204e37 | 6 | #include "graphics.h" |
embeddednerd | 0:0a2678204e37 | 7 | #include "MMA7660.h" |
embeddednerd | 0:0a2678204e37 | 8 | |
embeddednerd | 0:0a2678204e37 | 9 | |
embeddednerd | 0:0a2678204e37 | 10 | DigitalIn fire(p14); |
embeddednerd | 0:0a2678204e37 | 11 | PwmOut spkr(p26); |
embeddednerd | 0:0a2678204e37 | 12 | |
embeddednerd | 0:0a2678204e37 | 13 | C12832_LCD lcd; |
embeddednerd | 0:0a2678204e37 | 14 | |
embeddednerd | 0:0a2678204e37 | 15 | PwmOut r (p23); |
embeddednerd | 0:0a2678204e37 | 16 | PwmOut g (p24); |
embeddednerd | 0:0a2678204e37 | 17 | PwmOut b (p25); |
embeddednerd | 0:0a2678204e37 | 18 | |
embeddednerd | 0:0a2678204e37 | 19 | MMA7660 MMA(p28, p27); |
embeddednerd | 0:0a2678204e37 | 20 | |
embeddednerd | 0:0a2678204e37 | 21 | DigitalOut connectionLed(LED1); |
embeddednerd | 0:0a2678204e37 | 22 | PwmOut Zaxis_p(LED2); |
embeddednerd | 0:0a2678204e37 | 23 | PwmOut Zaxis_n(LED3); |
embeddednerd | 0:0a2678204e37 | 24 | |
embeddednerd | 0:0a2678204e37 | 25 | Mutex lcd_mutex; |
embeddednerd | 0:0a2678204e37 | 26 | |
embeddednerd | 0:0a2678204e37 | 27 | void Axisaccelerometer_thread(void const *args) |
embeddednerd | 0:0a2678204e37 | 28 | { |
embeddednerd | 0:0a2678204e37 | 29 | lcd_mutex.lock(); |
embeddednerd | 0:0a2678204e37 | 30 | |
embeddednerd | 0:0a2678204e37 | 31 | if (MMA.testConnection()) |
embeddednerd | 0:0a2678204e37 | 32 | connectionLed = 1; |
embeddednerd | 0:0a2678204e37 | 33 | |
embeddednerd | 0:0a2678204e37 | 34 | while(1) { |
embeddednerd | 0:0a2678204e37 | 35 | Zaxis_p = MMA.z(); |
embeddednerd | 0:0a2678204e37 | 36 | Zaxis_n = -MMA.z(); |
embeddednerd | 0:0a2678204e37 | 37 | |
embeddednerd | 0:0a2678204e37 | 38 | lcd_mutex.unlock(); |
embeddednerd | 0:0a2678204e37 | 39 | } |
embeddednerd | 0:0a2678204e37 | 40 | |
embeddednerd | 0:0a2678204e37 | 41 | } |
embeddednerd | 0:0a2678204e37 | 42 | |
embeddednerd | 0:0a2678204e37 | 43 | void RGB_thread(void const *args) |
embeddednerd | 0:0a2678204e37 | 44 | { |
embeddednerd | 0:0a2678204e37 | 45 | |
embeddednerd | 0:0a2678204e37 | 46 | r.period(0.001); |
embeddednerd | 0:0a2678204e37 | 47 | while(1) { |
embeddednerd | 0:0a2678204e37 | 48 | |
embeddednerd | 0:0a2678204e37 | 49 | for(float i = 0.0; i < 1.0 ; i += 0.001) { |
embeddednerd | 0:0a2678204e37 | 50 | float p = 3 * i; |
embeddednerd | 0:0a2678204e37 | 51 | r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); |
embeddednerd | 0:0a2678204e37 | 52 | g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); |
embeddednerd | 0:0a2678204e37 | 53 | b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; |
embeddednerd | 0:0a2678204e37 | 54 | wait (0.01); |
embeddednerd | 0:0a2678204e37 | 55 | } |
embeddednerd | 0:0a2678204e37 | 56 | |
embeddednerd | 0:0a2678204e37 | 57 | } |
embeddednerd | 0:0a2678204e37 | 58 | |
embeddednerd | 0:0a2678204e37 | 59 | } |
embeddednerd | 0:0a2678204e37 | 60 | |
embeddednerd | 0:0a2678204e37 | 61 | void ChristmasLCD_thread(void const *args) |
embeddednerd | 0:0a2678204e37 | 62 | { |
embeddednerd | 0:0a2678204e37 | 63 | |
embeddednerd | 0:0a2678204e37 | 64 | lcd_mutex.lock(); |
embeddednerd | 0:0a2678204e37 | 65 | |
embeddednerd | 0:0a2678204e37 | 66 | int i,s; |
embeddednerd | 0:0a2678204e37 | 67 | lcd.cls(); |
embeddednerd | 0:0a2678204e37 | 68 | lcd.set_font((unsigned char*) Arial_9); |
embeddednerd | 0:0a2678204e37 | 69 | s = 3; |
embeddednerd | 0:0a2678204e37 | 70 | lcd.print_bm(bitmTree,95,0); // print chistmas tree |
embeddednerd | 0:0a2678204e37 | 71 | lcd.copy_to_lcd(); |
embeddednerd | 0:0a2678204e37 | 72 | lcd.setmode(XOR); // XOR - a second print will erase |
embeddednerd | 0:0a2678204e37 | 73 | for(i = -15; i < 75; ){ |
embeddednerd | 0:0a2678204e37 | 74 | lcd.print_bm(bitmSan1,i,2); |
embeddednerd | 0:0a2678204e37 | 75 | wait(0.5); |
embeddednerd | 0:0a2678204e37 | 76 | lcd.copy_to_lcd(); // update lcd |
embeddednerd | 0:0a2678204e37 | 77 | lcd.print_bm(bitmSan1,i,2); // erase |
embeddednerd | 0:0a2678204e37 | 78 | i= i+s; |
embeddednerd | 0:0a2678204e37 | 79 | lcd.print_bm(bitmSan2,i,2); // print next |
embeddednerd | 0:0a2678204e37 | 80 | wait(0.5); |
embeddednerd | 0:0a2678204e37 | 81 | lcd.copy_to_lcd(); // update lcd |
embeddednerd | 0:0a2678204e37 | 82 | lcd.print_bm(bitmSan2,i,2); // erase |
embeddednerd | 0:0a2678204e37 | 83 | i= i+s; |
embeddednerd | 0:0a2678204e37 | 84 | lcd.print_bm(bitmSan3,i,2); // print next |
embeddednerd | 0:0a2678204e37 | 85 | wait(0.5); |
embeddednerd | 0:0a2678204e37 | 86 | lcd.copy_to_lcd(); // update lcd |
embeddednerd | 0:0a2678204e37 | 87 | lcd.print_bm(bitmSan3,i,2); // erase |
embeddednerd | 0:0a2678204e37 | 88 | i= i+s; |
embeddednerd | 0:0a2678204e37 | 89 | } |
embeddednerd | 0:0a2678204e37 | 90 | lcd.print_bm(bitmSan3,i,2); |
embeddednerd | 0:0a2678204e37 | 91 | lcd.set_auto_up(0); |
embeddednerd | 0:0a2678204e37 | 92 | for(i=-20; i<5; i++){ // scrolling text |
embeddednerd | 0:0a2678204e37 | 93 | lcd.locate(5,i); |
embeddednerd | 0:0a2678204e37 | 94 | lcd.printf("Happy"); |
embeddednerd | 0:0a2678204e37 | 95 | lcd.locate(5,i+12); |
embeddednerd | 0:0a2678204e37 | 96 | lcd.printf("Christmas"); |
embeddednerd | 0:0a2678204e37 | 97 | lcd.copy_to_lcd(); |
embeddednerd | 0:0a2678204e37 | 98 | lcd.locate(5,i); |
embeddednerd | 0:0a2678204e37 | 99 | wait(0.2); |
embeddednerd | 0:0a2678204e37 | 100 | lcd.printf("Happy"); |
embeddednerd | 0:0a2678204e37 | 101 | lcd.locate(5,i+12); |
embeddednerd | 0:0a2678204e37 | 102 | lcd.printf("Christmas"); |
embeddednerd | 0:0a2678204e37 | 103 | lcd.copy_to_lcd(); |
embeddednerd | 0:0a2678204e37 | 104 | i=i+1; |
embeddednerd | 0:0a2678204e37 | 105 | } |
embeddednerd | 0:0a2678204e37 | 106 | lcd.locate(5,i); |
embeddednerd | 0:0a2678204e37 | 107 | lcd.printf("Happy"); |
embeddednerd | 0:0a2678204e37 | 108 | lcd.locate(5,i+12); |
embeddednerd | 0:0a2678204e37 | 109 | lcd.printf("Christmas"); |
embeddednerd | 0:0a2678204e37 | 110 | lcd.copy_to_lcd(); |
embeddednerd | 0:0a2678204e37 | 111 | |
embeddednerd | 0:0a2678204e37 | 112 | lcd_mutex.unlock(); |
embeddednerd | 0:0a2678204e37 | 113 | |
embeddednerd | 0:0a2678204e37 | 114 | } |
embeddednerd | 0:0a2678204e37 | 115 | |
embeddednerd | 0:0a2678204e37 | 116 | int main() |
embeddednerd | 0:0a2678204e37 | 117 | { |
embeddednerd | 0:0a2678204e37 | 118 | Thread thread1(RGB_thread); |
embeddednerd | 0:0a2678204e37 | 119 | Thread thread2(ChristmasLCD_thread); |
embeddednerd | 0:0a2678204e37 | 120 | Thread thread3(Axisaccelerometer_thread); |
embeddednerd | 0:0a2678204e37 | 121 | |
embeddednerd | 0:0a2678204e37 | 122 | |
embeddednerd | 0:0a2678204e37 | 123 | while (1) { |
embeddednerd | 0:0a2678204e37 | 124 | |
embeddednerd | 0:0a2678204e37 | 125 | for (float i=2000.0; i<10000.0; i+=100) { |
embeddednerd | 0:0a2678204e37 | 126 | spkr.period(1.0/i); |
embeddednerd | 0:0a2678204e37 | 127 | spkr=0.5; |
embeddednerd | 0:0a2678204e37 | 128 | wait(0.1); |
embeddednerd | 0:0a2678204e37 | 129 | } |
embeddednerd | 0:0a2678204e37 | 130 | spkr=0.0; |
embeddednerd | 0:0a2678204e37 | 131 | while(!fire) {} |
embeddednerd | 0:0a2678204e37 | 132 | } |
embeddednerd | 0:0a2678204e37 | 133 | } |
embeddednerd | 0:0a2678204e37 | 134 |