![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
a
main.cpp@0:e08f7610c886, 2020-11-19 (annotated)
- Committer:
- tmnam0
- Date:
- Thu Nov 19 06:59:11 2020 +0000
- Revision:
- 0:e08f7610c886
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tmnam0 | 0:e08f7610c886 | 1 | /* |
tmnam0 | 0:e08f7610c886 | 2 | * Copyright (c) 2006-2020 Arm Limited and affiliates. |
tmnam0 | 0:e08f7610c886 | 3 | * SPDX-License-Identifier: Apache-2.0 |
tmnam0 | 0:e08f7610c886 | 4 | */ |
tmnam0 | 0:e08f7610c886 | 5 | |
tmnam0 | 0:e08f7610c886 | 6 | #include "mbed.h" |
tmnam0 | 0:e08f7610c886 | 7 | |
tmnam0 | 0:e08f7610c886 | 8 | static BufferedSerial pc(USBTX, USBRX); // tx, rx |
tmnam0 | 0:e08f7610c886 | 9 | PwmOut led(LED1); |
tmnam0 | 0:e08f7610c886 | 10 | |
tmnam0 | 0:e08f7610c886 | 11 | float brightness = 0.0; |
tmnam0 | 0:e08f7610c886 | 12 | |
tmnam0 | 0:e08f7610c886 | 13 | int main() |
tmnam0 | 0:e08f7610c886 | 14 | { |
tmnam0 | 0:e08f7610c886 | 15 | char msg[] = "Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"; |
tmnam0 | 0:e08f7610c886 | 16 | char *c = new char[1]; |
tmnam0 | 0:e08f7610c886 | 17 | pc.write(msg, sizeof(msg)); |
tmnam0 | 0:e08f7610c886 | 18 | |
tmnam0 | 0:e08f7610c886 | 19 | while (1) { |
tmnam0 | 0:e08f7610c886 | 20 | pc.read(c, sizeof(c)); |
tmnam0 | 0:e08f7610c886 | 21 | pc.write(c, sizeof(c)); |
tmnam0 | 0:e08f7610c886 | 22 | if ((*c == 'u') && (brightness < 0.5)) { |
tmnam0 | 0:e08f7610c886 | 23 | brightness += 0.01; |
tmnam0 | 0:e08f7610c886 | 24 | led = brightness; |
tmnam0 | 0:e08f7610c886 | 25 | } |
tmnam0 | 0:e08f7610c886 | 26 | if ((*c == 'd') && (brightness > 0.0)) { |
tmnam0 | 0:e08f7610c886 | 27 | brightness -= 0.01; |
tmnam0 | 0:e08f7610c886 | 28 | led = brightness; |
tmnam0 | 0:e08f7610c886 | 29 | } |
tmnam0 | 0:e08f7610c886 | 30 | } |
tmnam0 | 0:e08f7610c886 | 31 | |
tmnam0 | 0:e08f7610c886 | 32 | } |