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: LSM303DLHC RX8025 SDFileSystem TextLCD TouchSense mbed
Fork of MAPLEminiA by
main.cpp
00001 /* Sample for MAPLE-mini TypeA board(marutsu-elec MARM02-BASE) 00002 * マルツの MAPLE-mini TypeA基板(型番MARM02-BASE)用の動作確認用のプログラムです。 00003 * mbed1768での動作を確認しています。 00004 */ 00005 00006 #include "mbed.h" 00007 //液晶モジュール MI2CLCD-01 I2C(p28,p27) 00008 #include "TextLCD.h" 00009 //RTC RX-8025SA I2C(p28,p27) INTA-p25 INTB-p26 00010 #include "RX8025.h" 00011 //地磁気+加速度センサモジュール MLSM303DLHC I2C(p28,p27) 00012 #include "LSM303DLHC.h" 00013 //microSD card slot SPI(P5,p6,p7,CS-p22 CD1-p29) 00014 #include "SDFileSystem.h" 00015 //基板に作り込みの静電式タッチパッド p15~18 00016 #include "TouchSense.h" 00017 //圧電スピーカ p20 00018 //TypeB,C基板接続用コネクタ UART(p9,p10) I2C(p28,p27) 00019 00020 DigitalOut myled(LED1); 00021 00022 I2C i2c(p28,p27); // SDA, SCL 00023 TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); 00024 // LCD icon test patterns 00025 const int MAXICONS=13; 00026 struct { 00027 int8_t address; 00028 int8_t data; 00029 } const icons[MAXICONS] = { {0x00,0x10},{0x02,0x10},{0x04,0x10},{0x06, 0x10}, 00030 {0x07,0x10},{0x07,0x08},{0x09,0x10},{0x0b,0x10}, 00031 {0x0d,0x1e},{0x0d,0x1a},{0x0d,0x12},{0x0d,0x02}, 00032 {0x0f,0x10} }; 00033 00034 RX8025 rtc(i2c); 00035 LSM303DLHC compass(&i2c); 00036 00037 /* SD filesystem with card detection 00038 */ 00039 class SDFileSystemCD : public SDFileSystem { 00040 DigitalIn card_detect; 00041 public: 00042 SDFileSystemCD(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name) 00043 : SDFileSystem(p5, p6, p7, p22, "sd"), card_detect(cd, PullUp) { 00044 } 00045 bool cardExist(void) { return card_detect==0; } 00046 }; 00047 SDFileSystemCD sd(p5, p6, p7, p22, p29, "sd"); 00048 00049 //基板の裏側に触らないと ONにならない 00050 //構造的にそういう仕様っぽいけど、どうなんだろ? 00051 TouchSense sw1(p15),sw2(p16),sw3(p17),sw4(p18); 00052 00053 //圧電スピーカかp20に繋がっている 00054 //このボードのメインターゲットの MyARM基板では p20をPWMに出来るらしいけど 00055 //mbed1768では PWMに出来ないので DigitalOutで使用 00056 class MmASpeaker : public DigitalOut { 00057 public: 00058 MmASpeaker(PinName p) : DigitalOut(p) {} 00059 void beep(int32_t hz=1000, int32_t ms=100) { 00060 for(int i=0; i<hz*ms/1000; i++) { 00061 write(1); 00062 wait_us(1000*1000/hz/2); 00063 write(0); 00064 wait_us(1000*1000/hz/2); 00065 } 00066 } 00067 }; 00068 MmASpeaker speaker(p20); 00069 00070 int main() { 00071 lcd.setContrast(32); 00072 lcd.cls(); 00073 lcd.printf("Hello World!"); 00074 lcd.locate(0,1); 00075 if(sd.cardExist()) { 00076 lcd.printf("SDcard Exist"); 00077 mkdir("/sd/mydir", 0777); 00078 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); 00079 if(fp == NULL) { 00080 error("Could not open file for write\n"); 00081 } 00082 fprintf(fp, "Hello fun SD Card World!"); 00083 fclose(fp); 00084 } else lcd.printf("No SDcard"); 00085 Times t={0,0,0,0,0,0,0}; 00086 rtc.setTIME(t); 00087 sw1.calibration(); 00088 sw2.calibration(); 00089 sw3.calibration(); 00090 sw4.calibration(); 00091 wait(3.0); 00092 speaker.beep(); 00093 00094 int iconcounter=0; 00095 while(1) { 00096 Times t=rtc.getTIME(); 00097 compass.getAccel(); 00098 compass.getMagnet(); 00099 int sw=(((sw1.sense()<<1 | sw2.sense())<<1) | sw3.sense())<<1 |sw4.sense(); 00100 speaker.beep(1600/sw); 00101 00102 lcd.locate(0,0); 00103 lcd.printf("%1x %.1f %d ", sw, compass.temperature(), compass.accelX()); 00104 lcd.locate(0,1); 00105 lcd.printf("%02X:%02X:%02X %.1f", t.hours, t.minutes, t.seconds, compass.orientation()); 00106 lcd.clrIcon(); 00107 lcd.setIcon(icons[iconcounter].address,icons[iconcounter].data); 00108 if(++iconcounter >= MAXICONS) iconcounter=0; 00109 myled = 1; 00110 wait(0.2); 00111 myled = 0; 00112 wait(0.2); 00113 } 00114 }
Generated on Thu Jul 14 2022 10:47:25 by
1.7.2
