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.
Dependencies: MMA8451Q Multi_WS2811 NVIC_set_all_priorities TSI cc3000_hostdriver_mbedsocket mbed
Fork of CubicHand by
Revision 24:554ea084eddf, committed 2014-12-11
- Comitter:
- joseoyola
- Date:
- Thu Dec 11 04:23:31 2014 +0000
- Parent:
- 21:5b987194387d
- Child:
- 25:7a866b3d79bb
- Commit message:
- Added LED code for 3D effect by lighting all panels with different brightness.
Changed in this revision
| ledCube.cpp | Show annotated file Show diff for this revision Revisions of this file |
| ledCube.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ledCube.cpp Wed Dec 10 22:46:44 2014 +0000
+++ b/ledCube.cpp Thu Dec 11 04:23:31 2014 +0000
@@ -44,7 +44,7 @@
g = 255*0.1;
b = 255*0.1;
- brightness = 0.05;
+ brightness = 0.5;
saturation = 1.0;
ledStrip1.begin();
@@ -84,6 +84,51 @@
void LedCube::updateLEDs(bool on, int size, int x, int y, int z) {
//Panel 1
+ double bright;
+ bright = 1.0 / ((y + 1) * (y + 1));
+ printf("Panel 1 Brightness: %f\r\n", bright);
+ for(int i = x; i < x + size; i++) {
+ for(int j = z; j < z + size; j++) {
+ int led = getLedIndex(PANEL1, i, j);
+ if(on) {
+ ledStrip1.setPixelColor(led, r*bright, g*bright, b*bright);
+ } else {
+ ledStrip1.setPixelColor(led, 0, 0, 0);
+ }
+ }
+ }
+
+ //Panel 2
+ bright = 1.0 / (((nCOLs-1) - x - (size-1) + 1) * ((nCOLs-1) - x - (size-1) + 1));
+ printf("Panel 2 Brightness: %f\r\n", bright);
+ for(int i = y; i < y + size; i++) {
+ for(int j = z; j < z + size; j++) {
+ int led = getLedIndex(PANEL2, i, j);
+ if(on) {
+ ledStrip1.setPixelColor(led, r*bright, g*bright, b*bright);
+ } else {
+ ledStrip1.setPixelColor(led, 0, 0, 0);
+ }
+ }
+ }
+
+ //Panel 3
+ bright = 1.0 / (((nCOLs-1) - z - (size-1) + 1) * ((nCOLs-1) - z - (size-1) + 1));
+ printf("Panel 3 Brightness: %f\r\n", bright);
+ for(int i = x; i < x + size; i++) {
+ for(int j = y; j < y + size; j++) {
+ int led = getLedIndex(PANEL3, i, j);
+ if(on) {
+ ledStrip2.setPixelColor(led, r*bright, g*bright, b*bright);
+ } else {
+ ledStrip2.setPixelColor(led, 0, 0, 0);
+ }
+ }
+ }
+}
+
+void LedCube::updateLEDsOld(bool on, int size, int x, int y, int z) {
+ //Panel 1
if(y == 0) {
for(int i = x; i < x + size; i++) {
for(int j = z; j < z + size; j++) {
--- a/ledCube.h Wed Dec 10 22:46:44 2014 +0000
+++ b/ledCube.h Thu Dec 11 04:23:31 2014 +0000
@@ -11,6 +11,7 @@
void Init(int x, int y, int z);
int getLedIndex(int panel, int x, int y);
void updateLEDs(bool on, int size, int x, int y, int z);
+ void updateLEDsOld(bool on, int size, int x, int y, int z);
void cubeUpdate();
int move(int deltaX, int deltaY, int deltaZ);
void changeColor(float hue);
