Skip to content

Commit d4195c5

Browse files
committed
improvement to mbed example
1 parent 89aa6df commit d4195c5

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

examples/mbedAdaExample/main.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* An example that shows how to render using an SSD1306 display for text
3+
* and graphics. It should compile for most mbed 5 and 6 boards.
4+
* Use build flag BUILD_FOR_MBED_6 to target mbed 6.
5+
*/
16

27
#include <cstdio>
38
#include <TaskManager.h>
@@ -9,14 +14,17 @@
914
#include <Fonts/FreeSans9pt7b.h>
1015

1116
// Host PC Communication channels
12-
BufferedSerial pc(USBTX, USBRX); // tx, rx
13-
FILE* serPort = fdopen(&pc, "w");
17+
#ifdef BUILD_FOR_MBED_6
18+
BufferedSerial pc(USBTX, USBRX);
19+
#else
20+
Serial pc(USBTX, USBRX);
21+
#endif
1422
MBedLogger LoggingPort(pc);
1523

1624
//I2C i2c(PF_0,PF_1);
1725
//Adafruit_SSD1306_I2c gfx(i2c, NC, SSD_I2C_ADDRESS, 64, 132, SH_1106);
1826

19-
SPI spi(PA_7, PA_6, PA_5);
27+
SPI spi(PB_5, PB_4, PB_3);
2028
Adafruit_SSD1306_Spi gfx(spi, PD_15, PF_12, PF_13, 64, 128, SSD_1306);
2129

2230
bool exitApp = false;
@@ -27,24 +35,29 @@ const uint8_t iconWifiThreeBar[] = {
2735
};
2836
int main()
2937
{
38+
#ifdef BUILD_FOR_MBED_6
39+
pc.set_baud(115200);
40+
#else
41+
pc.baud(115200);
42+
#endif
43+
3044
//i2c.frequency(400000);
3145
gfx.begin();
32-
pc.set_baud(115200);
33-
fprintf(serPort, "Hello from mbed graphics demo\n");
46+
serdebugF("Hello from mbed graphics demo");
3447

3548
switches.initialise(internalDigitalIo(), true);
3649
switches.addSwitch(PE_4, [] (pinid_t id, bool held) {
37-
fprintf(serPort, "Switch Pressed %d, %d\n", (int)id, (int) held);
50+
serdebugF3("Switch Pressed", (int)id, (int) held);
3851
});
3952
switches.addSwitch(USER_BUTTON, [] (pinid_t id, bool held) {
40-
fprintf(serPort, "User Pressed %d, %d\n", (int)id, (int) held);
53+
serdebugF3("User Pressed", (int)id, (int) held);
4154
}, NO_REPEAT, true);
4255

4356
setupRotaryEncoderWithInterrupt(PE_2, PE_5, []( int val) {
44-
fprintf(serPort, "Encoder %d\n", val);
57+
serdebugF2("Encoder", val);
4558
});
4659

47-
fprintf(serPort, "Created\n");
60+
serdebugF("Created");
4861

4962
// Display with the Adafruit Library
5063
gfx.clearDisplay();

0 commit comments

Comments
 (0)