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:
- 2:f2700008c9d9
- Child:
- 3:da30c350c339
diff -r 53b8c6b13010 -r f2700008c9d9 Cube/LedCube.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Cube/LedCube.cpp Thu May 01 20:58:59 2014 +0000
@@ -0,0 +1,87 @@
+#include "LedCube.h"
+
+LedCube::LedCube(){
+ //construct needed arrays to store the output values
+ status = address;
+
+ layer_current=0;
+ rank_current=0;
+ layer_oneHot=1;
+}
+//return the next byte of data to send
+char LedCube::getNextValue(){
+
+ char output;
+ switch(status){
+ case address :
+ output = layer_oneHot;
+ status=red; // next time give red color
+ break;
+ case red :
+ output = rValues[layer_current][rank_current];//return red value
+ if(rank_current!=7)rank_current++;
+ else {
+ status = green; // next time give green color
+ rank_current =0; //put the rank back on zero
+ }
+ break;
+ case green :
+ output = gValues[layer_current][rank_current];//return green value
+ if(rank_current!=7)rank_current++;
+ else {
+ status = blue; // next time give blue color
+ rank_current =0; //put the rank back on zero
+ }
+ break;
+ case blue :
+ output = bValues[layer_current][rank_current];//return blue value
+ if(rank_current!=7)rank_current++;
+ else {
+ status = address; // next time give address color
+ rank_current =0; //put the rank back on zero
+ layer_oneHot = layer_oneHot << 1;
+ if(layer_current!=7)layer_current++;
+ else layer_current=0;
+ if(layer_oneHot == 0) layer_oneHot = 1;
+ }
+ break;
+ }
+ return output;
+}
+//setData set the arrays to the new frame
+void LedCube::setData(char* data){
+ //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
+ for(int j = 0; j < 8; j++) {
+ int y = j * 8; //a row is 8 elements
+ char weight = 128;
+ for(int k = 0; k < 8; k++) { //iterate for each element
+ char digitbuffer = data[z+y+k]; //read byte consisting of color 1 led
+ //now select the right color
+ if(k == 0) {
+ rValues[i][j] = 0;
+ gValues[i][j] = 0;
+ bValues[i][j] = 0;
+ }
+ if(digitbuffer >= 4) {
+ rValues[i][j] += weight;
+ digitbuffer = digitbuffer - 4;
+ }
+ if(digitbuffer >= 2) {
+ gValues[i][j] += weight;
+ digitbuffer = digitbuffer - 2;
+ }
+ if(digitbuffer >= 1) {
+ bValues[i][j] += weight;
+ }
+ weight = weight >> 1;
+ }
+ }
+ }
+}
+
+void LedCube::testMode(){
+ rValues[4][2] = 255;
+}
+