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:02946956d93e, committed 2018-01-30
- Comitter:
- bjs9
- Date:
- Tue Jan 30 22:06:06 2018 +0000
- Child:
- 1:ff9797f5be2c
- Commit message:
- Lab3 code;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Tue Jan 30 22:06:06 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RGB_LED.h Tue Jan 30 22:06:06 2018 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+
+class RGBLed
+{
+public:
+ RGBLed(PinName redpin, PinName greenpin, PinName bluepin);
+ void write(float red,float green, float blue);
+private:
+ PwmOut _redpin;
+ PwmOut _greenpin;
+ PwmOut _bluepin;
+};
+
+RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin)
+ : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin)
+{
+ //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker)
+ _redpin.period(0.0005);
+}
+
+void RGBLed::write(float red,float green, float blue)
+{
+ _redpin = red;
+ _greenpin = green;
+ _bluepin = blue;
+}
+//class could be moved to include file
+
+
+//Sestup RGB led using PWM pins and class
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Jan 30 22:06:06 2018 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "PinDetect.h"
+#include "RGB_LED.h"
+
+RGBLed myRGBled(p22,p23,p24);
+PinDetect pb1(p16);
+PinDetect pb2(p17);
+DigitalIn switchInputRed(p13);
+DigitalIn switchInputBlue(p14);
+DigitalIn switchInputGreen(p15);
+
+
+float illuminateRed = 0.0f;
+float illuminateBlue = 0.0f;
+float illuminateGreen = 0.0f;
+bool greenOn =false;
+bool blueOn = false;
+bool redOn = false;
+
+
+void pb1_dim_callback (void) {
+ if(redOn && illuminateRed > 0.0f){
+ illuminateRed -= 0.1f;
+ }
+ if(greenOn && illuminateGreen > 0.0f){
+ illuminateGreen -= 0.1f;
+ }
+ if(blueOn && illuminateBlue > 0.0f) {
+ illuminateBlue -= 0.1f;
+ }
+ }
+void pb2_bright_callback (void) {
+ if(redOn && illuminateRed <= 1.0f){
+ illuminateRed += 0.1f;
+ }
+ if(greenOn && illuminateGreen <= 1.0f){
+ illuminateGreen += 0.1f;
+ }
+ if(blueOn && illuminateBlue <= 1.0f) {
+ illuminateBlue += 0.1f;
+ }
+ }
+int main() {
+ switchInputRed.mode(PullUp);
+ switchInputGreen.mode(PullUp);
+ switchInputBlue.mode(PullUp);
+ pb1.mode(PullUp);
+ pb2.mode(PullUp);
+ wait(.01);
+
+ pb1.attach_deasserted(&pb1_dim_callback);
+ pb2.attach_deasserted(&pb2_bright_callback);
+
+ pb1.setSampleFrequency();
+ pb2.setSampleFrequency();
+
+ while(1) {
+ redOn = switchInputRed;
+ blueOn = switchInputBlue;
+ greenOn = switchInputGreen;
+ myRGBled.write(illuminateRed,illuminateGreen,illuminateBlue);
+ wait(.1);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jan 30 22:06:06 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e \ No newline at end of file