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.
Diff: Cube/LedCube.cpp
- Revision:
- 3:da30c350c339
- Parent:
- 2:f2700008c9d9
- Child:
- 4:a091b8f8216d
diff -r f2700008c9d9 -r da30c350c339 Cube/LedCube.cpp
--- a/Cube/LedCube.cpp Thu May 01 20:58:59 2014 +0000
+++ b/Cube/LedCube.cpp Fri May 02 18:26:40 2014 +0000
@@ -8,17 +8,21 @@
rank_current=0;
layer_oneHot=1;
}
+
+LedCube::~LedCube(){
+}
+
//return the next byte of data to send
char LedCube::getNextValue(){
- char output;
+ char bytevalue;
switch(status){
case address :
- output = layer_oneHot;
+ bytevalue = layer_oneHot;
status=red; // next time give red color
break;
case red :
- output = rValues[layer_current][rank_current];//return red value
+ bytevalue = rValues[layer_current][rank_current];//return red value
if(rank_current!=7)rank_current++;
else {
status = green; // next time give green color
@@ -26,7 +30,7 @@
}
break;
case green :
- output = gValues[layer_current][rank_current];//return green value
+ bytevalue = gValues[layer_current][rank_current];//return green value
if(rank_current!=7)rank_current++;
else {
status = blue; // next time give blue color
@@ -34,7 +38,7 @@
}
break;
case blue :
- output = bValues[layer_current][rank_current];//return blue value
+ bytevalue = bValues[layer_current][rank_current];//return blue value
if(rank_current!=7)rank_current++;
else {
status = address; // next time give address color
@@ -46,10 +50,14 @@
}
break;
}
- return output;
+ return bytevalue;
}
//setData set the arrays to the new frame
void LedCube::setData(char* data){
+ printf("Converting following data: \n\r");
+ for(int i = 0; i < 512; i++) printf("%d ", data[i]);
+ printf("\n\r\n\r");
+
//convert raw data to rgb values
for(int i = 0; i < 8; i++) { //char array (afkomstig van raspberry pi) omzetten naar rgb matrix (voor ledcube)
int z = i * 64; // a layer is 64 byte
@@ -79,9 +87,58 @@
}
}
}
+ printf("Result: \n\r");
+ printAll();
+ printf("Conversion terminated\n\r");
+}
+
+void LedCube::testMode(TestConfig testconfig){
+ char leddata[512];
+ switch(testconfig){
+ case LedCube::firsthalfwhite :
+ for(int i = 0; i < 256; i++) leddata[i] = 7;
+ for(int i = 256; i < 512; i++) leddata[i] = 0;
+ break;
+ case LedCube::secondhalfwhite :
+ for(int i = 0; i < 256; i++) leddata[i] = 0;
+ for(int i = 256; i < 512; i++) leddata[i] = 7;
+ break;
+ }
+ setData(leddata);
}
-void LedCube::testMode(){
- rValues[4][2] = 255;
+void LedCube::printrValues(){
+ for(int i = 0; i < 8; i ++){
+ for(int j = 0; j < 8; j++){
+ printf("%d ", rValues[i][j]);
+ }
+ printf("\n\r");
+ }
+}
+
+void LedCube::printgValues(){
+ for(int i = 0; i < 8; i ++){
+ for(int j = 0; j < 8; j++){
+ printf("%d ", gValues[i][j]);
+ }
+ printf("\n\r");
+ }
}
+void LedCube::printbValues(){
+ for(int i = 0; i < 8; i ++){
+ for(int j = 0; j < 8; j++){
+ printf("%d ", bValues[i][j]);
+ }
+ printf("\n\r");
+ }
+}
+
+void LedCube::printAll(){
+ printf("Red Matrix: \n\r");
+ printrValues();
+ printf("\n\rGreen Matrix: \n\r");
+ printgValues();
+ printf("\n\rBlue Matrix: \n\r");
+ printbValues();
+}