Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832_lcd LCD_fonts LM75B MMA7660 mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "C12832_lcd.h" 00004 #include "Arial_9.h" 00005 #include "Small_7.h" 00006 #include "graphics.h" 00007 #include "MMA7660.h" 00008 00009 00010 DigitalIn fire(p14); 00011 PwmOut spkr(p26); 00012 00013 C12832_LCD lcd; 00014 00015 PwmOut r (p23); 00016 PwmOut g (p24); 00017 PwmOut b (p25); 00018 00019 MMA7660 MMA(p28, p27); 00020 00021 DigitalOut connectionLed(LED1); 00022 PwmOut Zaxis_p(LED2); 00023 PwmOut Zaxis_n(LED3); 00024 00025 Mutex lcd_mutex; 00026 00027 void Axisaccelerometer_thread(void const *args) 00028 { 00029 lcd_mutex.lock(); 00030 00031 if (MMA.testConnection()) 00032 connectionLed = 1; 00033 00034 while(1) { 00035 Zaxis_p = MMA.z(); 00036 Zaxis_n = -MMA.z(); 00037 00038 lcd_mutex.unlock(); 00039 } 00040 00041 } 00042 00043 void RGB_thread(void const *args) 00044 { 00045 00046 r.period(0.001); 00047 while(1) { 00048 00049 for(float i = 0.0; i < 1.0 ; i += 0.001) { 00050 float p = 3 * i; 00051 r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); 00052 g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); 00053 b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; 00054 wait (0.01); 00055 } 00056 00057 } 00058 00059 } 00060 00061 void ChristmasLCD_thread(void const *args) 00062 { 00063 00064 lcd_mutex.lock(); 00065 00066 int i,s; 00067 lcd.cls(); 00068 lcd.set_font((unsigned char*) Arial_9); 00069 s = 3; 00070 lcd.print_bm(bitmTree,95,0); // print chistmas tree 00071 lcd.copy_to_lcd(); 00072 lcd.setmode(XOR); // XOR - a second print will erase 00073 for(i = -15; i < 75; ){ 00074 lcd.print_bm(bitmSan1,i,2); 00075 wait(0.5); 00076 lcd.copy_to_lcd(); // update lcd 00077 lcd.print_bm(bitmSan1,i,2); // erase 00078 i= i+s; 00079 lcd.print_bm(bitmSan2,i,2); // print next 00080 wait(0.5); 00081 lcd.copy_to_lcd(); // update lcd 00082 lcd.print_bm(bitmSan2,i,2); // erase 00083 i= i+s; 00084 lcd.print_bm(bitmSan3,i,2); // print next 00085 wait(0.5); 00086 lcd.copy_to_lcd(); // update lcd 00087 lcd.print_bm(bitmSan3,i,2); // erase 00088 i= i+s; 00089 } 00090 lcd.print_bm(bitmSan3,i,2); 00091 lcd.set_auto_up(0); 00092 for(i=-20; i<5; i++){ // scrolling text 00093 lcd.locate(5,i); 00094 lcd.printf("Happy"); 00095 lcd.locate(5,i+12); 00096 lcd.printf("Christmas"); 00097 lcd.copy_to_lcd(); 00098 lcd.locate(5,i); 00099 wait(0.2); 00100 lcd.printf("Happy"); 00101 lcd.locate(5,i+12); 00102 lcd.printf("Christmas"); 00103 lcd.copy_to_lcd(); 00104 i=i+1; 00105 } 00106 lcd.locate(5,i); 00107 lcd.printf("Happy"); 00108 lcd.locate(5,i+12); 00109 lcd.printf("Christmas"); 00110 lcd.copy_to_lcd(); 00111 00112 lcd_mutex.unlock(); 00113 00114 } 00115 00116 int main() 00117 { 00118 Thread thread1(RGB_thread); 00119 Thread thread2(ChristmasLCD_thread); 00120 Thread thread3(Axisaccelerometer_thread); 00121 00122 00123 while (1) { 00124 00125 for (float i=2000.0; i<10000.0; i+=100) { 00126 spkr.period(1.0/i); 00127 spkr=0.5; 00128 wait(0.1); 00129 } 00130 spkr=0.0; 00131 while(!fire) {} 00132 } 00133 } 00134
Generated on Sat Aug 13 2022 01:23:24 by
