First Last
/
BMT-K9_if_then_else
if then else demo with potmeter
Revision 0:e381f9305692, committed 2013-09-24
- Comitter:
- vsluiter
- Date:
- Tue Sep 24 15:17:40 2013 +0000
- Commit message:
- Initial Commit;
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 e381f9305692 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 24 15:17:40 2013 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" + +// redled is an object of class PwmOut. It uses the LED_RED pin +// in human speech: redled is an output that can be controlled with PWM. LED_RED is the pin which is connected to the output +PwmOut redled(LED_RED); + +//ditto... +PwmOut greenled(LED_GREEN); +PwmOut blueled(LED_BLUE); + +// pot is an object of class AnalogIn. It uses the PTB0 pin +// in human speech: pot is an analog input. You can read the voltage on pin PTB0 +AnalogIn pot(PTB0); + + +//start 'main' function. Should be done once in every C(++) program +int main() +{ + float potvalue; + //setup some stuff + //period of PWM signal is 10kHz. Every 100 microsecond a new PWM period is started + redled.period_ms(0.1); + greenled.period_ms(0.1); + blueled.period_ms(0.1); + //while 1 is unequal to zero. For humans: loop forever + while(1) + { + //limit loop time + wait(0.01); + //read potentiometer, store in potvalue + potvalue = pot.read(); + if(potvalue < 0.33) + { + redled = 1-potvalue; //subtract from 1 to get high value (almost off) at potmeter maximum + greenled = 1; //off + blueled = 1; //off + } + else // value greater or equal to 0.33 + { + if(potvalue < 0.66) + { + redled = 1-potvalue; + greenled = 1-potvalue; + blueled = 1; + } + else //value greater or equal to 0.66 + { + redled = 1-potvalue; + greenled = 1-potvalue; + blueled = 1-potvalue; + } + } + } +} +
diff -r 000000000000 -r e381f9305692 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Sep 24 15:17:40 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file