Tj Maher
/
Colourmixer
Use the Analog pots to mix 2 colours ,red and green, print the analog values of the pot every 0.5 secs.
main.cpp@0:c3c42383ed71, 2019-05-22 (annotated)
- Committer:
- t00203959
- Date:
- Wed May 22 11:09:18 2019 +0000
- Revision:
- 0:c3c42383ed71
Use the Analog pots on the mbed board and mix 2 colours red and green and print the values of the pot every 0.5 seconds.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t00203959 | 0:c3c42383ed71 | 1 | #include "mbed.h" |
t00203959 | 0:c3c42383ed71 | 2 | |
t00203959 | 0:c3c42383ed71 | 3 | AnalogIn mypotentiometer1 (p19); // reads potentiometer1 value |
t00203959 | 0:c3c42383ed71 | 4 | AnalogIn mypotentiometer2 (p20); // reads potentiometer2 value |
t00203959 | 0:c3c42383ed71 | 5 | |
t00203959 | 0:c3c42383ed71 | 6 | PwmOut red(p24); // initilizes red led |
t00203959 | 0:c3c42383ed71 | 7 | PwmOut green(p25); // initilizes green led |
t00203959 | 0:c3c42383ed71 | 8 | |
t00203959 | 0:c3c42383ed71 | 9 | float p1, p2; // creates float for both potentiometer values |
t00203959 | 0:c3c42383ed71 | 10 | |
t00203959 | 0:c3c42383ed71 | 11 | Serial pc(USBTX, USBRX); // initilizes output to Tera Term |
t00203959 | 0:c3c42383ed71 | 12 | |
t00203959 | 0:c3c42383ed71 | 13 | int main() |
t00203959 | 0:c3c42383ed71 | 14 | { |
t00203959 | 0:c3c42383ed71 | 15 | while(1) { |
t00203959 | 0:c3c42383ed71 | 16 | p1 = mypotentiometer1 * 100; // converts signal to value between 0 and 1 |
t00203959 | 0:c3c42383ed71 | 17 | p2 = mypotentiometer2 * 100; // converts signal to value between 0 and 1 |
t00203959 | 0:c3c42383ed71 | 18 | { |
t00203959 | 0:c3c42383ed71 | 19 | red = mypotentiometer1; // assigns red led to potentiometer1 |
t00203959 | 0:c3c42383ed71 | 20 | green = mypotentiometer2; // assigns green led to potentiometer2 |
t00203959 | 0:c3c42383ed71 | 21 | |
t00203959 | 0:c3c42383ed71 | 22 | } |
t00203959 | 0:c3c42383ed71 | 23 | wait(0.5); // time in secs mbed checks potentiometer values |
t00203959 | 0:c3c42383ed71 | 24 | pc.printf("%f \n\r", mypotentiometer1.read()); // prints reading on Tera Term for potentiometer 1 value |
t00203959 | 0:c3c42383ed71 | 25 | pc.printf("%f \n\r", mypotentiometer2.read()); // prints reading on Tera Term for potentiometer 2 value |
t00203959 | 0:c3c42383ed71 | 26 | } |
t00203959 | 0:c3c42383ed71 | 27 | } |