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.
main.cpp@0:5d6f30101feb, 2015-09-20 (annotated)
- Committer:
- ceojoe
- Date:
- Sun Sep 20 21:50:37 2015 +0000
- Revision:
- 0:5d6f30101feb
Problem 1 - Output random value to onboard LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ceojoe | 0:5d6f30101feb | 1 | #include "mbed.h" |
ceojoe | 0:5d6f30101feb | 2 | #include "SLCD.h" |
ceojoe | 0:5d6f30101feb | 3 | |
ceojoe | 0:5d6f30101feb | 4 | #define DATATIME 250 // 250 milliseconds |
ceojoe | 0:5d6f30101feb | 5 | #define LASTDGDIV 10 |
ceojoe | 0:5d6f30101feb | 6 | #define PROGNAME "JChac_341_4_2_Analog Rand v1\n\r" |
ceojoe | 0:5d6f30101feb | 7 | |
ceojoe | 0:5d6f30101feb | 8 | AnalogIn analogRand(PTB0); |
ceojoe | 0:5d6f30101feb | 9 | DigitalOut Rled(LED_RED); |
ceojoe | 0:5d6f30101feb | 10 | Serial pc(USBTX, USBRX); |
ceojoe | 0:5d6f30101feb | 11 | |
ceojoe | 0:5d6f30101feb | 12 | SLCD slcd; // New instance of LCD |
ceojoe | 0:5d6f30101feb | 13 | |
ceojoe | 0:5d6f30101feb | 14 | |
ceojoe | 0:5d6f30101feb | 15 | void LCDMess(unsigned int lMess){ |
ceojoe | 0:5d6f30101feb | 16 | slcd.Home(); |
ceojoe | 0:5d6f30101feb | 17 | slcd.clear(); |
ceojoe | 0:5d6f30101feb | 18 | slcd.printf("%d", lMess); |
ceojoe | 0:5d6f30101feb | 19 | } |
ceojoe | 0:5d6f30101feb | 20 | |
ceojoe | 0:5d6f30101feb | 21 | int main() |
ceojoe | 0:5d6f30101feb | 22 | { |
ceojoe | 0:5d6f30101feb | 23 | float analogValue; |
ceojoe | 0:5d6f30101feb | 24 | unsigned int analogBits; |
ceojoe | 0:5d6f30101feb | 25 | unsigned int lastDigit; |
ceojoe | 0:5d6f30101feb | 26 | pc.printf(PROGNAME); |
ceojoe | 0:5d6f30101feb | 27 | while (true) { |
ceojoe | 0:5d6f30101feb | 28 | analogValue = analogRand.read(); |
ceojoe | 0:5d6f30101feb | 29 | analogBits = analogRand.read_u16(); |
ceojoe | 0:5d6f30101feb | 30 | lastDigit = analogBits % LASTDGDIV; |
ceojoe | 0:5d6f30101feb | 31 | Rled = !Rled; // toggle red |
ceojoe | 0:5d6f30101feb | 32 | LCDMess(lastDigit); |
ceojoe | 0:5d6f30101feb | 33 | pc.printf("%0.5f, %d, %1d\n\r", analogValue, analogBits, lastDigit); |
ceojoe | 0:5d6f30101feb | 34 | wait_ms(DATATIME); |
ceojoe | 0:5d6f30101feb | 35 | } |
ceojoe | 0:5d6f30101feb | 36 | } |