Forum Index > Projects > LED Pegboard and Matrix Projects
 [Meggy Jr program] Color Cube
 |  Printable Version
By: Anonymous: Alexandre () on Sunday, December 28 2008 @ 10:26 AM PST (Read 2915 times)  
Anonymous: Alexandre

Could not find the attachment feature, so here it is ...

/*
ColorCube - Displays all colors in the RGB cube
Version 1.0 - 12/27/2008
Copyright (c) 2008 Nicolas and Alexandre Ganivet. All rights reserved.

This programs visualizes the RGB color cube on the Meggy Jr display.
It initially displays the Red/Green face of the cube, with the A/B buttons
controlling the depth on the Blue axis. You can therefore visualize all
possible colors that can be displayed on the Meggy Jr display.

For an additional twist, the directional buttons do rotate the cube, allowing
you to visualize all other faces of the color cube. It takes a little effort
to make sense of it though!

This program uses the SetPxClr routine, which directly writes to the
Meggy Jr video buffer, setting the color of an individual dot in the RGB matrix

*/

#include <MeggyJrSimple.h> // Required

int XAxis, YAxis, ZAxis; // MUST be of type 'int' since will store negative values
byte Depth;

#define Red 1;
#define Green 2;
#define Blue 3;

void setup()
{
MeggyJrSimpleSetup(); // Initialize MeggyJr library

// Initial orientation and depth of cube
XAxis = Red;
YAxis = Green;
ZAxis = Blue;
Depth = 0;
}


void loop()
{
uint8_t Color[3];
byte x, y, xind, yind, zind;
int t; // MUST be of type 'int' since will store negative values

/******************************************/
/* Check for button presses and act on it */
/******************************************/
CheckButtonsPress();

// Manage depth change (Z axis, A/B buttons)
if (Button_A && (Depth<7)) {
Depth++;
}
if (Button_B && (Depth>0)) {
Depth--;
}

// Manage cube rotations (directional buttons)
if (Button_Up) {
t = ZAxis;
ZAxis = -YAxis;
YAxis = t;
}
if (Button_Down) {
t = ZAxis;
ZAxis = YAxis;
YAxis =-t;
}
if (Button_Left) {
t = ZAxis;
ZAxis = -XAxis;
XAxis = t;
}
if (Button_Right) {
t = ZAxis;
ZAxis = XAxis;
XAxis = -t;
}

/****************************************/
/* Refresh main display with color cube */
/****************************************/
// Display depth on Aux LEDs
Meg.AuxLEDs = 1 << Depth;

// Initialize axis indexes
xind = abs(XAxis)-1;
yind = abs(YAxis)-1;
zind = abs(ZAxis)-1;

// Loop over main display
Color[zind] = (ZAxis<0 ? 7-Depth : Depth )*2;
Color[xind] = (XAxis<0 ?14:0);
for (x=0; x<8; x++) {
Color[yind] = (YAxis<0?14:0);
for (y=0; y<8; y++) {
Meg.SetPxClr(x, y, Color);
Color[yind] += (YAxis<0?-2:2);
}
Color[xind] += (XAxis<0?-2:2);
}

// End of main loop
}





       
   
By: Windell (offline) on Sunday, December 28 2008 @ 11:18 AM PST  
Windell

Neat! Our "official" place for contributed code is our Google Code page, http://code.google.com/p/meggy-jr-rgb/. If you would like to open-source your code and become one of the developers on this project, please send us an E-mail message through our Contact Form.


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   



 All times are PDT. The time is now 12:02 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?