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.
Fork of Wio_3G_example by
main.cpp@71:7d17edde2e03, 2018-08-03 (annotated)
- Committer:
- MACRUM
- Date:
- Fri Aug 03 06:46:00 2018 +0000
- Revision:
- 71:7d17edde2e03
- Parent:
- 70:cb6d36218441
- Child:
- 72:aa14c091f860
Remove 4-Digit display, add Grove LCD RGB backlight
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
| MACRUM | 71:7d17edde2e03 | 2 | #include "Grove_LCD_RGB_Backlight.h" |
| MACRUM | 70:cb6d36218441 | 3 | |
| MACRUM | 70:cb6d36218441 | 4 | #define D20 (PB_4) |
| MACRUM | 70:cb6d36218441 | 5 | #define D19 (PB_3) |
| MACRUM | 70:cb6d36218441 | 6 | |
| MACRUM | 70:cb6d36218441 | 7 | DigitalOut GrovePower(PB_10, 1); |
| MACRUM | 70:cb6d36218441 | 8 | DigitalOut led1(D38); |
| MACRUM | 70:cb6d36218441 | 9 | AnalogIn ain(A6); |
| MACRUM | 70:cb6d36218441 | 10 | InterruptIn btn(D20); |
| MACRUM | 71:7d17edde2e03 | 11 | Grove_LCD_RGB_Backlight rgbLCD(I2C_SDA, I2C_SCL); |
| MACRUM | 70:cb6d36218441 | 12 | |
| MACRUM | 71:7d17edde2e03 | 13 | uint32_t button = 0; |
| MACRUM | 70:cb6d36218441 | 14 | |
| MACRUM | 70:cb6d36218441 | 15 | /// |
| MACRUM | 70:cb6d36218441 | 16 | |
| MACRUM | 70:cb6d36218441 | 17 | float get_temp() |
| MACRUM | 70:cb6d36218441 | 18 | { |
| MACRUM | 70:cb6d36218441 | 19 | const int B = 4275; // B value of the thermistor |
| MACRUM | 70:cb6d36218441 | 20 | const int R0 = 100000; // R0 = 100k |
| MACRUM | 70:cb6d36218441 | 21 | AnalogIn temp(A4); |
| MACRUM | 71:7d17edde2e03 | 22 | |
| MACRUM | 70:cb6d36218441 | 23 | float R = 1.0f/temp.read() - 1.0f; |
| MACRUM | 70:cb6d36218441 | 24 | R = R0*R; |
| Jonathan Austin |
0:2757d7abb7d9 | 25 | |
| MACRUM | 70:cb6d36218441 | 26 | float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet |
| MACRUM | 70:cb6d36218441 | 27 | return temperature; |
| MACRUM | 70:cb6d36218441 | 28 | } |
| MACRUM | 70:cb6d36218441 | 29 | /// |
| MACRUM | 70:cb6d36218441 | 30 | |
| MACRUM | 70:cb6d36218441 | 31 | |
| MACRUM | 70:cb6d36218441 | 32 | void push() |
| MACRUM | 70:cb6d36218441 | 33 | { |
| MACRUM | 71:7d17edde2e03 | 34 | button++; |
| MACRUM | 70:cb6d36218441 | 35 | } |
| Jonathan Austin |
0:2757d7abb7d9 | 36 | |
| Jonathan Austin |
1:846c97078558 | 37 | // main() runs in its own thread in the OS |
| MACRUM | 70:cb6d36218441 | 38 | int main() |
| MACRUM | 70:cb6d36218441 | 39 | { |
| MACRUM | 70:cb6d36218441 | 40 | btn.fall(push); |
| MACRUM | 70:cb6d36218441 | 41 | |
| MACRUM | 71:7d17edde2e03 | 42 | rgbLCD.clear(); |
| MACRUM | 71:7d17edde2e03 | 43 | rgbLCD.setRGB(0xff, 0x00, 0x00); |
| MACRUM | 71:7d17edde2e03 | 44 | rgbLCD.locate(0, 0); |
| MACRUM | 71:7d17edde2e03 | 45 | rgbLCD.print("Hello World!"); |
| MACRUM | 71:7d17edde2e03 | 46 | rgbLCD.locate(0, 1); |
| MACRUM | 71:7d17edde2e03 | 47 | rgbLCD.print("This is a test"); |
| MACRUM | 71:7d17edde2e03 | 48 | |
| MACRUM | 70:cb6d36218441 | 49 | int cnt = 0; |
| MACRUM | 70:cb6d36218441 | 50 | printf("hello, Mbed world\n"); |
| Jonathan Austin |
0:2757d7abb7d9 | 51 | while (true) { |
| MACRUM | 71:7d17edde2e03 | 52 | printf("count = %4d, button = %d, analog = %f, temp = %f\n", cnt++, button, ain.read(), get_temp()); |
| Jonathan Austin |
0:2757d7abb7d9 | 53 | led1 = !led1; |
| mbed_official | 22:af9dcf379926 | 54 | wait(0.5); |
| Jonathan Austin |
0:2757d7abb7d9 | 55 | } |
| Jonathan Austin |
0:2757d7abb7d9 | 56 | } |
| Jonathan Austin |
1:846c97078558 | 57 |
