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:a64f45869df3, committed 2015-02-18
- Comitter:
- lzzcd001
- Date:
- Wed Feb 18 14:48:48 2015 +0000
- Commit message:
- Extra problem 2 for HW 1
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 Wed Feb 18 14:48:48 2015 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+
+DigitalOut latch(p15);
+DigitalOut enable(p16);
+DigitalIn r(p5);
+DigitalIn g(p6);
+DigitalIn b(p7);
+
+SPI spi(p11, p12, p13);
+
+void RGB_LED(int red, int green, int blue) {
+ unsigned int low_color=0;
+ unsigned int high_color=0;
+ high_color=(blue<<4)|((red&0x3C0)>>6);
+ low_color=(((red&0x3F)<<10)|(green));
+ spi.write(high_color);
+ spi.write(low_color);
+ latch=1;
+ latch=0;
+}
+
+int main() {
+ int red=0;
+ int green=0;
+ int blue=0;
+ spi.format(16,0);
+ spi.frequency(500000);
+ enable=0;
+ latch=0;
+ wait(2);
+ while(1) {
+ if (r == 1){
+ if (red < 255) red += 5;
+ } else {
+ if (red > 0) red -= 5;
+ }
+ if (b == 1){
+ if (blue < 255) blue += 5;
+ } else {
+ if (blue > 0) blue -= 5;
+ }
+ if (g == 1){
+ if (green < 255) green += 5;
+ } else {
+ if (green > 0) green -= 5;
+ }
+ RGB_LED(red, green, blue);
+ wait(0.5);
+ }
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Feb 18 14:48:48 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file