![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Publish_MAPLEminiA
Dependencies: LSM303DLHC RX8025 SDFileSystem TextLCD TouchSense mbed
Fork of MAPLEminiA by
main.cpp@1:707a0a314781, 2016-06-05 (annotated)
- Committer:
- jk1lot
- Date:
- Sun Jun 05 11:19:13 2016 +0000
- Revision:
- 1:707a0a314781
- Parent:
- 0:06047ad53505
- Child:
- 3:aae83c4bd9a0
published version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jk1lot | 1:707a0a314781 | 1 | /* Sample for MAPLE-mini TypeA board(marutsu-elec MARM02-BASE) |
jk1lot | 1:707a0a314781 | 2 | * マルツの MAPLE-mini TypeA基板(型番MARM02-BASE)用の動作確認用のプログラムです。 |
jk1lot | 1:707a0a314781 | 3 | */ |
jk1lot | 1:707a0a314781 | 4 | |
jk1lot | 0:06047ad53505 | 5 | #include "mbed.h" |
jk1lot | 1:707a0a314781 | 6 | //液晶モジュール MI2CLCD-01 I2C(p28,p27) |
jk1lot | 0:06047ad53505 | 7 | #include "TextLCD.h" |
jk1lot | 1:707a0a314781 | 8 | //RTC RX-8025SA I2C(p28,p27) INTA-p25 INTB-p26 |
jk1lot | 0:06047ad53505 | 9 | #include "RX8025.h" |
jk1lot | 1:707a0a314781 | 10 | //地磁気+加速度センサモジュール MLSM303DLHC I2C(p28,p27) |
jk1lot | 0:06047ad53505 | 11 | #include "LSM303DLH.h" |
jk1lot | 1:707a0a314781 | 12 | //microSD card slot SPI(P5,p6,p7,CS-p22 CD1-p29) |
jk1lot | 0:06047ad53505 | 13 | #include "SDFileSystem.h" |
jk1lot | 1:707a0a314781 | 14 | //基板に作り込みの静電式タッチパッド p15~18 |
jk1lot | 0:06047ad53505 | 15 | #include "TouchSense.h" |
jk1lot | 1:707a0a314781 | 16 | //圧電スピーカ p20 |
jk1lot | 1:707a0a314781 | 17 | //TypeB,C基板接続用コネクタ UART(p9,p10) I2C(p28,p27) |
jk1lot | 1:707a0a314781 | 18 | |
jk1lot | 1:707a0a314781 | 19 | DigitalOut myled(LED1); |
jk1lot | 0:06047ad53505 | 20 | |
jk1lot | 0:06047ad53505 | 21 | I2C i2c(p28,p27); // SDA, SCL |
jk1lot | 0:06047ad53505 | 22 | TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); |
jk1lot | 0:06047ad53505 | 23 | RX8025 rtc(i2c); |
jk1lot | 0:06047ad53505 | 24 | LSM303DLH compass(p28, p27); |
jk1lot | 0:06047ad53505 | 25 | SDFileSystem sd(p5, p6, p7, p22, "sd"); |
jk1lot | 1:707a0a314781 | 26 | |
jk1lot | 1:707a0a314781 | 27 | //基板の裏側に触らないと ONにならない |
jk1lot | 1:707a0a314781 | 28 | //構造的にそういう仕様っぽいけど、どうなんだろ? |
jk1lot | 0:06047ad53505 | 29 | TouchSense sw1(p15),sw2(p16),sw3(p17),sw4(p18); |
jk1lot | 0:06047ad53505 | 30 | |
jk1lot | 1:707a0a314781 | 31 | //圧電スピーカかp20に繋がっている |
jk1lot | 1:707a0a314781 | 32 | //このボードのメインターゲットの MyARM基板では p20をPWMに出来るらしいけど |
jk1lot | 1:707a0a314781 | 33 | //mbed1768では PWMに出来ないので DigitalOutで使用 |
jk1lot | 0:06047ad53505 | 34 | class MmASpeaker : public DigitalOut { |
jk1lot | 0:06047ad53505 | 35 | public: |
jk1lot | 0:06047ad53505 | 36 | MmASpeaker(PinName p) : DigitalOut(p) {} |
jk1lot | 0:06047ad53505 | 37 | void beep(int32_t hz=1000, int32_t ms=100) { |
jk1lot | 0:06047ad53505 | 38 | for(int i=0; i<hz*ms/1000; i++) { |
jk1lot | 0:06047ad53505 | 39 | write(1); |
jk1lot | 0:06047ad53505 | 40 | wait_us(1000*1000/hz/2); |
jk1lot | 0:06047ad53505 | 41 | write(0); |
jk1lot | 0:06047ad53505 | 42 | wait_us(1000*1000/hz/2); |
jk1lot | 0:06047ad53505 | 43 | } |
jk1lot | 0:06047ad53505 | 44 | } |
jk1lot | 0:06047ad53505 | 45 | }; |
jk1lot | 0:06047ad53505 | 46 | MmASpeaker speaker(p20); |
jk1lot | 0:06047ad53505 | 47 | |
jk1lot | 0:06047ad53505 | 48 | int main() { |
jk1lot | 0:06047ad53505 | 49 | lcd.cls(); |
jk1lot | 0:06047ad53505 | 50 | lcd.printf("Hello World!\n"); |
jk1lot | 0:06047ad53505 | 51 | /* SDカードのテストをするときにはコメントを外してね |
jk1lot | 0:06047ad53505 | 52 | mkdir("/sd/mydir", 0777); |
jk1lot | 0:06047ad53505 | 53 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
jk1lot | 0:06047ad53505 | 54 | if(fp == NULL) { |
jk1lot | 0:06047ad53505 | 55 | error("Could not open file for write\n"); |
jk1lot | 0:06047ad53505 | 56 | } |
jk1lot | 0:06047ad53505 | 57 | fprintf(fp, "Hello fun SD Card World!"); |
jk1lot | 0:06047ad53505 | 58 | fclose(fp); |
jk1lot | 0:06047ad53505 | 59 | */ |
jk1lot | 0:06047ad53505 | 60 | Times t={0,0,0,0,0,0,0}; |
jk1lot | 0:06047ad53505 | 61 | rtc.setTIME(t); |
jk1lot | 0:06047ad53505 | 62 | compass.setOffset(0.00, 0.00, 0.00); |
jk1lot | 0:06047ad53505 | 63 | compass.setScale(1.00, 1.00, 1.00); |
jk1lot | 0:06047ad53505 | 64 | sw1.calibration(); |
jk1lot | 0:06047ad53505 | 65 | sw2.calibration(); |
jk1lot | 0:06047ad53505 | 66 | sw3.calibration(); |
jk1lot | 0:06047ad53505 | 67 | sw4.calibration(); |
jk1lot | 0:06047ad53505 | 68 | speaker.beep(); |
jk1lot | 0:06047ad53505 | 69 | |
jk1lot | 0:06047ad53505 | 70 | while(1) { |
jk1lot | 0:06047ad53505 | 71 | Times t=rtc.getTIME(); |
jk1lot | 0:06047ad53505 | 72 | float hdg = compass.heading(); |
jk1lot | 0:06047ad53505 | 73 | bool s1=sw1.sense(),s2=sw2.sense(),s3=sw3.sense(),s4=sw4.sense(); |
jk1lot | 0:06047ad53505 | 74 | |
jk1lot | 0:06047ad53505 | 75 | if(s1) speaker.beep(200); |
jk1lot | 0:06047ad53505 | 76 | else if(s2) speaker.beep(400); |
jk1lot | 0:06047ad53505 | 77 | else if(s3) speaker.beep(800); |
jk1lot | 0:06047ad53505 | 78 | else if(s4) speaker.beep(1600); |
jk1lot | 0:06047ad53505 | 79 | |
jk1lot | 0:06047ad53505 | 80 | lcd.locate(0,0); |
jk1lot | 0:06047ad53505 | 81 | lcd.printf("%d %d %d %d ",s1,s2,s3,s4); |
jk1lot | 0:06047ad53505 | 82 | lcd.locate(0,1); |
jk1lot | 0:06047ad53505 | 83 | lcd.printf("%02X:%02X:%02X %.2f", t.hours, t.minutes, t.seconds, hdg); |
jk1lot | 0:06047ad53505 | 84 | myled = 1; |
jk1lot | 0:06047ad53505 | 85 | wait(0.2); |
jk1lot | 0:06047ad53505 | 86 | myled = 0; |
jk1lot | 0:06047ad53505 | 87 | wait(0.2); |
jk1lot | 0:06047ad53505 | 88 | } |
jk1lot | 0:06047ad53505 | 89 | } |