This program displays a series of text messages on a 16x2 line LCD and also then displays the room temperature taken from a TMP102 I2C module. It represents my first attempt to do anything useful with an mbed which is something I got my hands on less than 4 days ago. It shows what can be achieved by someone who has no prior knowledge of C after about 4 hours of tinkering with various sample programs. This code itself took me around 40 minutes of that 4 hours of play time to craft. The LCD is hooked up to the mbed as per the TextLCD program instructions. The TMP102 module is hooked up as per the TMP102HelloWorld program instructions. If you want to hook up some of the more complex components in your Cool Components starter kit and see them work in a matter of minutes, this little showcase program will do just that. Enjoy. Thanks to whoever wrote the libraries and original code which I used.
Dependencies: TextLCD mbed TMP102
main.cpp@0:9f9af3710502, 2012-04-21 (annotated)
- Committer:
- bigweggy
- Date:
- Sat Apr 21 10:54:24 2012 +0000
- Revision:
- 0:9f9af3710502
This program is a quick mash up which I made up from 2 other programs found on the cookbook. It is a combination of the TextLCD code and the TMP102HelloWorld program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bigweggy | 0:9f9af3710502 | 1 | // Hello World! for the TextLCD |
bigweggy | 0:9f9af3710502 | 2 | |
bigweggy | 0:9f9af3710502 | 3 | #include "mbed.h" |
bigweggy | 0:9f9af3710502 | 4 | #include "TextLCD.h" |
bigweggy | 0:9f9af3710502 | 5 | #include "TMP102.h" |
bigweggy | 0:9f9af3710502 | 6 | |
bigweggy | 0:9f9af3710502 | 7 | TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 |
bigweggy | 0:9f9af3710502 | 8 | TMP102 temperature(p9, p10, 0x90); //A0 pin is connected to ground |
bigweggy | 0:9f9af3710502 | 9 | int main() { |
bigweggy | 0:9f9af3710502 | 10 | while (1) { |
bigweggy | 0:9f9af3710502 | 11 | lcd.printf("Hello.I'm MBED. "); |
bigweggy | 0:9f9af3710502 | 12 | lcd.printf("Microcontroller "); |
bigweggy | 0:9f9af3710502 | 13 | wait(3); |
bigweggy | 0:9f9af3710502 | 14 | |
bigweggy | 0:9f9af3710502 | 15 | lcd.printf("Rapid Protoyping"); |
bigweggy | 0:9f9af3710502 | 16 | lcd.printf("System created "); |
bigweggy | 0:9f9af3710502 | 17 | wait(3); |
bigweggy | 0:9f9af3710502 | 18 | |
bigweggy | 0:9f9af3710502 | 19 | lcd.printf("by ARM-Cambridge"); |
bigweggy | 0:9f9af3710502 | 20 | lcd.printf("That's ENGLAND!"); |
bigweggy | 0:9f9af3710502 | 21 | wait(3); |
bigweggy | 0:9f9af3710502 | 22 | |
bigweggy | 0:9f9af3710502 | 23 | lcd.printf("You can write "); |
bigweggy | 0:9f9af3710502 | 24 | lcd.printf("a program for me"); |
bigweggy | 0:9f9af3710502 | 25 | wait(3); |
bigweggy | 0:9f9af3710502 | 26 | |
bigweggy | 0:9f9af3710502 | 27 | lcd.printf("quickly & easily"); |
bigweggy | 0:9f9af3710502 | 28 | lcd.printf("using the online"); |
bigweggy | 0:9f9af3710502 | 29 | wait(3); |
bigweggy | 0:9f9af3710502 | 30 | |
bigweggy | 0:9f9af3710502 | 31 | lcd.printf("C compiler in "); |
bigweggy | 0:9f9af3710502 | 32 | lcd.printf("the cloud. There"); |
bigweggy | 0:9f9af3710502 | 33 | wait(3); |
bigweggy | 0:9f9af3710502 | 34 | |
bigweggy | 0:9f9af3710502 | 35 | lcd.printf("is also a vast "); |
bigweggy | 0:9f9af3710502 | 36 | lcd.printf("cookbook online "); |
bigweggy | 0:9f9af3710502 | 37 | wait(3); |
bigweggy | 0:9f9af3710502 | 38 | |
bigweggy | 0:9f9af3710502 | 39 | lcd.printf("where you can "); |
bigweggy | 0:9f9af3710502 | 40 | lcd.printf("find lots of "); |
bigweggy | 0:9f9af3710502 | 41 | wait(3); |
bigweggy | 0:9f9af3710502 | 42 | |
bigweggy | 0:9f9af3710502 | 43 | lcd.printf("example code to "); |
bigweggy | 0:9f9af3710502 | 44 | lcd.printf("experiment with "); |
bigweggy | 0:9f9af3710502 | 45 | wait(3); |
bigweggy | 0:9f9af3710502 | 46 | |
bigweggy | 0:9f9af3710502 | 47 | lcd.printf("to create "); |
bigweggy | 0:9f9af3710502 | 48 | lcd.printf("programs like "); |
bigweggy | 0:9f9af3710502 | 49 | wait(3); |
bigweggy | 0:9f9af3710502 | 50 | |
bigweggy | 0:9f9af3710502 | 51 | lcd.printf("this one in "); |
bigweggy | 0:9f9af3710502 | 52 | lcd.printf("minutes! "); |
bigweggy | 0:9f9af3710502 | 53 | wait(3); |
bigweggy | 0:9f9af3710502 | 54 | |
bigweggy | 0:9f9af3710502 | 55 | lcd.printf(" "); |
bigweggy | 0:9f9af3710502 | 56 | lcd.printf(" "); |
bigweggy | 0:9f9af3710502 | 57 | wait(3); |
bigweggy | 0:9f9af3710502 | 58 | |
bigweggy | 0:9f9af3710502 | 59 | lcd.printf("Temp is: "); |
bigweggy | 0:9f9af3710502 | 60 | lcd.printf("%.1f degrees C\n", temperature.read()) ; |
bigweggy | 0:9f9af3710502 | 61 | wait(3); |
bigweggy | 0:9f9af3710502 | 62 | |
bigweggy | 0:9f9af3710502 | 63 | } |
bigweggy | 0:9f9af3710502 | 64 | } |