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.
Revision 6:5e143cfa91fe, committed 2020-02-10
- Comitter:
- lamjohbak
- Date:
- Mon Feb 10 10:28:51 2020 +0000
- Parent:
- 5:a89ad54e5ac7
- Commit message:
- Control Led with Potentiometer
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a89ad54e5ac7 -r 5e143cfa91fe main.cpp --- a/main.cpp Tue Sep 19 19:25:46 2017 +0000 +++ b/main.cpp Mon Feb 10 10:28:51 2020 +0000 @@ -3,17 +3,29 @@ C12832 lcd(D11, D13, D12, D7, D10); +PwmOut r (D5); +PwmOut g (D8); +PwmOut b (D9); + AnalogIn pot1 (A0); AnalogIn pot2 (A1); int main() { + r.period(0.001); + while(1) { lcd.cls(); lcd.locate(0,3); lcd.printf("Pot 1 = %.2f", (float)pot1); lcd.locate(0,14); lcd.printf("Pot 2 = %.2f", (float)pot2); - wait(0.1); + float i = (float)pot1; + float p = 3 * i; + r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); + g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); + b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; + wait (0.01); + } }