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 0:6d39248e2786, committed 2021-03-26
- Comitter:
- BertieHarte
- Date:
- Fri Mar 26 10:16:37 2021 +0000
- Commit message:
- make public
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 26 10:16:37 2021 +0000 @@ -0,0 +1,56 @@ +//Write a program to turn on LED if analog value from any of the potentimeter is greater than 50% and turn it off when the value is less than or equal to 50%. + +//copy and paste the final code you have in the answer section. + +#include "mbed.h" +DigitalOut R(p23); //Red pin of RGB LED + +DigitalOut G(p24); //Green pin of RGB LED + +DigitalOut B(p25); //Blue pin of RGB LED + +AnalogIn pot1(p19);// input from pot 1 + +AnalogIn pot2(p20);// input from pot 2 + +void on(){ // function to turn on white LED + +R = G = B = 0; + +} + +void off(){ // function to turn off white led + +R = G = B = 1; + +} + +int main() { + +R = G = B = 1; // init RGB led to off (all 1) + +while(1) + +{ + +float p1 = (pot1*100); // converts the pot reading to % (multiple by 100) + +float p2 = (pot2*100); // converts the pot reading to % (multiple by 100) + +if(p1 >50 || p2 >50){ // if value of p1 OR p2 > 50 (technically 50.00...) the LED will turn on. + +on(); // call function "on" + +} + +else // if the float value of either p1 or p2 is less than or equal to 50 (technically 50.00...) the LEd will go off. + +{ + +off(); // call function "off" + +} + +} + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 26 10:16:37 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file