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
Diff: main.cpp
- Revision:
- 0:06047ad53505
- Child:
- 1:707a0a314781
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Jun 05 05:15:19 2016 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "RX8025.h"
+#include "LSM303DLH.h"
+#include "SDFileSystem.h"
+#include "TouchSense.h"
+
+I2C i2c(p28,p27); // SDA, SCL
+TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3);
+RX8025 rtc(i2c);
+LSM303DLH compass(p28, p27);
+SDFileSystem sd(p5, p6, p7, p22, "sd");
+TouchSense sw1(p15),sw2(p16),sw3(p17),sw4(p18);
+
+class MmASpeaker : public DigitalOut {
+public:
+ MmASpeaker(PinName p) : DigitalOut(p) {}
+ void beep(int32_t hz=1000, int32_t ms=100) {
+ for(int i=0; i<hz*ms/1000; i++) {
+ write(1);
+ wait_us(1000*1000/hz/2);
+ write(0);
+ wait_us(1000*1000/hz/2);
+ }
+ }
+};
+MmASpeaker speaker(p20);
+
+DigitalOut myled(LED1);
+
+int main() {
+ lcd.cls();
+ lcd.printf("Hello World!\n");
+/* SDカードのテストをするときにはコメントを外してね
+ mkdir("/sd/mydir", 0777);
+ FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+ if(fp == NULL) {
+ error("Could not open file for write\n");
+ }
+ fprintf(fp, "Hello fun SD Card World!");
+ fclose(fp);
+*/
+ Times t={0,0,0,0,0,0,0};
+ rtc.setTIME(t);
+ compass.setOffset(0.00, 0.00, 0.00);
+ compass.setScale(1.00, 1.00, 1.00);
+ sw1.calibration();
+ sw2.calibration();
+ sw3.calibration();
+ sw4.calibration();
+ speaker.beep();
+
+ while(1) {
+ Times t=rtc.getTIME();
+ float hdg = compass.heading();
+ bool s1=sw1.sense(),s2=sw2.sense(),s3=sw3.sense(),s4=sw4.sense();
+
+ if(s1) speaker.beep(200);
+ else if(s2) speaker.beep(400);
+ else if(s3) speaker.beep(800);
+ else if(s4) speaker.beep(1600);
+
+ lcd.locate(0,0);
+ lcd.printf("%d %d %d %d ",s1,s2,s3,s4);
+ lcd.locate(0,1);
+ lcd.printf("%02X:%02X:%02X %.2f", t.hours, t.minutes, t.seconds, hdg);
+ myled = 1;
+ wait(0.2);
+ myled = 0;
+ wait(0.2);
+ }
+}
