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 8:c06f5046c9f7, committed 2014-12-05
- Comitter:
- joseoyola
- Date:
- Fri Dec 05 22:20:34 2014 +0000
- Parent:
- 6:9a6c0c98e694
- Child:
- 9:6d122c16efb7
- Commit message:
- Added more functions to led.cpp
Changed in this revision
| led.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/led.cpp Fri Dec 05 21:41:25 2014 +0000
+++ b/led.cpp Fri Dec 05 22:20:34 2014 +0000
@@ -23,14 +23,14 @@
#define PANEL3 2
int pos[3];
-int size;
+int size = 0;
// per LED: 3 * 20 mA = 60mA max
// 60 LEDs: 60 * 60mA = 3600 mA max
// 120 LEDs: 7200 mA max
unsigned const nLEDs = 60;//MAX_LEDS_PER_STRIP;
-unsigned const nROWs = 3;
-unsigned const nCOLs = 20;
+unsigned const nROWs = 10;
+unsigned const nCOLs = 10;
@@ -42,6 +42,7 @@
unsigned const DATA_OUT_PIN1 = 2; // PTD2
unsigned const DATA_OUT_PIN2 = 3; // PTD3
+unsigned const DATA_OUT_PIN3 = 4; // PTD3
Serial pc(USBTX, USBRX);
Timer timeRunning;
@@ -67,11 +68,11 @@
WS2811 lightStrip1(nLEDs, DATA_OUT_PIN1);
WS2811 lightStrip2(nLEDs, DATA_OUT_PIN2);
-
+WS2811 lightStrip3(nLEDs, DATA_OUT_PIN2);
void readTouchSensor()
{
- touchPercentage *= 0.9;
+ touchPercentage *= 0.(nCOLs - 1);
touchPercentage += touchSensor.readPercentage() * 0.1;
brite = minBrite + (maxBrite - minBrite) * touchPercentage;
}
@@ -79,22 +80,22 @@
void move(deltaX, deltaY, deltaZ) {
//Moving in X direction
- if(pos[Y] == 0 || pos[Z] == 9) { //Making sure square is "stuck" to panel 1 or 3
- if((pos[X] + size + deltaX) < 10 && (pos[X] + deltaX) >= 0) {
+ if(pos[Y] == 0 || pos[Z] == (nCOLs - 1)) { //Making sure square is "stuck" to panel 1 or 3
+ if((pos[X] + size + deltaX) < nCOLs && (pos[X] + deltaX) >= 0) {
pos[X] += deltaX;
}
}
//Moving in Y direction
- if(pos[X] == 9 || pos[Z] == 9) {//Making sure square is "stuck" to panel 2 or 3
- if((pos[Y] + size + deltaY) < 10 && (pos[Y] + deltaY) >= 0) {
+ if(pos[X] == (nCOLs - 1) || pos[Z] == (nCOLs - 1)) {//Making sure square is "stuck" to panel 2 or 3
+ if((pos[Y] + size + deltaY) < nCOLs && (pos[Y] + deltaY) >= 0) {
pos[Y] += deltaY;
}
}
//Moving in Z direction
- if(pos[X] == 9 || pos[Y] == 0) {//Making sure square is "stuck" to panel 1 or 2
- if((pos[Z] + size + deltaZ) < 10 && (pos[Z] + deltaZ) >= 0) {
+ if(pos[X] == (nCOLs - 1) || pos[Y] == 0) {//Making sure square is "stuck" to panel 1 or 2
+ if((pos[Z] + size + deltaZ) < nCOLs && (pos[Z] + deltaZ) >= 0) {
pos[Z] += deltaZ;
}
}
@@ -123,14 +124,28 @@
}
//Panel 2
- if(pos[X] + size == 0) {
- for(int i = pos[X]; i < pos[X] + size; i++) {
+ if(pos[X] + size == (nCOLs - 1)) {
+ for(int i = pos[Y]; i < pos[Y] + size; i++) {
for(int j = pos[Z]; j < pos[Z] + size; j++) {
- int led = getLedIndex(PANEL1, i, j);
+ int led = getLedIndex(PANEL2, i, j);
if(on) {
- ledStrip1(led, r, g, b);
+ ledStrip2(led, r, g, b);
} else {
- ledStrip1(led, 0, 0, 0);
+ ledStrip2(led, 0, 0, 0);
+ }
+ }
+ }
+ }
+
+ //Panel 3
+ if(pos[Z] + size == (nCOLs - 1)) {
+ for(int i = pos[X]; i < pos[X] + size; i++) {
+ for(int j = pos[Y]; j < pos[Y] + size; j++) {
+ int led = getLedIndex(PANEL3, i, j);
+ if(on) {
+ ledStrip3(led, r, g, b);
+ } else {
+ ledStrip3(led, 0, 0, 0);
}
}
}
@@ -140,18 +155,40 @@
-static int matrixtolinear(int x, int y) {
- int pos;
- if( x % 2 == 0) {
- pos = (x*nCOLs) +y;
+
+
+static int getLedIndex(int panel, int x, int y) {
+ if (panel == PANEL1) {
+ if (y % 2 == 0) {
+ return nCOLs*2 * y + x;
+ }
+ else {
+ return nCOLs*2 * y + nCOLs + ((nCOLs - 1) - x);
+ }
}
- else {
- pos = (x*nCOLs) + ((nCOLs-1)-y);
+
+ if (panel == PANEL2) {
+ if (y % 2 == 0) {
+ return nCOLs*2 * y + nCOLs + x;
+ }
+ else {
+ return nCOLs*2 * y + ((nCOLs - 1) - x);
+ }
}
- return pos;
+
+ if (panel == PANEL3) {
+ if (y % 2 == 0) {
+ return nCOLs * y + x;
+ }
+ else {
+ return nCOLs * y + ((nCOLs - 1) - x);
+ }
+ }
+
+ else return -1;
}
-
+/*
static void move( int delta_x, int delta_y, int old_size, int new_size)
{
for( int i = pos_y; i < pos_y + old_size; i++){
@@ -182,10 +219,4 @@
lightStrip1.startDMA();
lightStrip2.startDMA();
}
-
-//Set initial position and size
-void init(void) {
- pos_x = 0;
- pos_y = 0;
- size = 2;
-}
\ No newline at end of file
+*/
\ No newline at end of file
