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:325feea5981d, committed 2021-03-26
- Comitter:
- BertieHarte
- Date:
- Fri Mar 26 10:20:02 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 |
diff -r 000000000000 -r 325feea5981d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 26 10:20:02 2021 +0000 @@ -0,0 +1,35 @@ +//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) +// printf("pot1 value = %f \n \r", p1); + // printf("pot2 value = %f \n \r", p2); + 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" + } + } +} +
diff -r 000000000000 -r 325feea5981d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 26 10:20:02 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file