-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated gradient to work with shortest distance only
- Loading branch information
Showing
3 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This is my adventure in writing software for the [Illuminato x Machina](http://illuminatolabs.com/IlluminatoXMachina.htm). | ||
|
||
The IXM is an interesting platform, taking the limits of a [von Neumann](http://en.wikipedia.org/wiki/John_von_Neumann) and twisting them by adding additional, closely connected computation units. Basically giving you a tiny network of computers that are self aware, robust, and viral (in a sense). It behaves similar to an [Arduino](http://www.arduino.cc/) in that it has a bootloader which is programmable through a USB/Serial connection. It can communicate on each of it's four sides and provide small visual feedback with LEDs on each edge and a centrally located RGB LED. | ||
|
||
I picked up a [Comp Sci Hack Pack](http://www.liquidware.com/shop/show/CS-HP/Comp+Sci+Hack+Pack), which includes a red programming terminal and 3 IXM cells. This allows for some parallel computations and other interesting experiments. | ||
|
||
The files contained below are compilable and executable on each IXM cell. | ||
|
||
References: | ||
|
||
* [http://illuminatolabs.com/IlluminatoXMachina.htm]() | ||
* [http://robust.cs.unm.edu/doku.php]() | ||
* [http://livingcomputation.com/s/doc/Tutorials.html]() | ||
* [http://livingcomputation.com/s/doc/index.html]() | ||
* [http://www.liquidware.com/shop/show/IXM/Illuminato+X+Machina]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,100 @@ | ||
// Simple Gradient | ||
// (C) 2010 Jacob Good | ||
// License: MIT (included in LICENSE.txt) | ||
// | ||
// Notes: This demonstrates a gradient based on distance from the center. | ||
// Each IXM cell responds to a click and sets itself as center, | ||
// broadcasting it's event and passing around distance calculations, | ||
// out over the graph. Each cell then turns on a set of LEDs to | ||
// indicate it's *shortest* distance from the center. | ||
|
||
u32 shortestDistance; | ||
|
||
void setRed( void ) { | ||
ledOn(BODY_RGB_RED_PIN); | ||
ledOff(BODY_RGB_BLUE_PIN); | ||
ledOff(BODY_RGB_GREEN_PIN); | ||
ledOff(BODY_RGB_BLUE_PIN); | ||
ledOff(BODY_RGB_GREEN_PIN); | ||
} | ||
|
||
void setBlue( void ) { | ||
ledOff(BODY_RGB_RED_PIN); | ||
ledOn(BODY_RGB_BLUE_PIN); | ||
ledOff(BODY_RGB_GREEN_PIN); | ||
ledOn(BODY_RGB_BLUE_PIN); | ||
ledOff(BODY_RGB_GREEN_PIN); | ||
} | ||
|
||
void setGreen( void ) { | ||
ledOff(BODY_RGB_RED_PIN); | ||
ledOff(BODY_RGB_BLUE_PIN); | ||
ledOn(BODY_RGB_GREEN_PIN); | ||
ledOff(BODY_RGB_BLUE_PIN); | ||
ledOn(BODY_RGB_GREEN_PIN); | ||
} | ||
|
||
void setWhite( void ) { | ||
ledOn(BODY_RGB_RED_PIN); | ||
ledOn(BODY_RGB_BLUE_PIN); | ||
ledOn(BODY_RGB_GREEN_PIN); | ||
ledOn(BODY_RGB_BLUE_PIN); | ||
ledOn(BODY_RGB_GREEN_PIN); | ||
} | ||
|
||
void setBlack( void ) { | ||
ledOff(BODY_RGB_RED_PIN); | ||
ledOff(BODY_RGB_BLUE_PIN); | ||
ledOff(BODY_RGB_GREEN_PIN); | ||
ledOff(BODY_RGB_BLUE_PIN); | ||
ledOff(BODY_RGB_GREEN_PIN); | ||
} | ||
|
||
void branch( u32 sourceFace, u32 distance ) { | ||
void branchGradient( u32 sourceFace, u32 distance ) { | ||
if (sourceFace != NORTH) facePrintf(NORTH,"g%d\n",distance); | ||
if (sourceFace != SOUTH) facePrintf(SOUTH,"g%d\n",distance); | ||
if (sourceFace != EAST) facePrintf(EAST,"g%d\n",distance); | ||
if (sourceFace != WEST) facePrintf(WEST,"g%d\n",distance); | ||
} | ||
|
||
void setGradient( u8 * packet ) { | ||
void branchReset( u32 sourceFace ) { | ||
if (sourceFace != NORTH) facePrintf(NORTH,"r\n"); | ||
if (sourceFace != SOUTH) facePrintf(SOUTH,"r\n"); | ||
if (sourceFace != EAST) facePrintf(EAST,"r\n"); | ||
if (sourceFace != WEST) facePrintf(WEST,"r\n"); | ||
} | ||
|
||
void handleGradient( u8 * packet ) { | ||
u32 distance; | ||
packetScanf(packet,"g%d\n",&distance); | ||
|
||
setBlack(); | ||
if (distance >= shortestDistance) return; | ||
|
||
shortestDistance = distance; | ||
|
||
if (distance == 1) setBlue(); | ||
else if (distance == 2) setGreen(); | ||
else if (distance == 3) setWhite(); | ||
|
||
branch(packetSource(packet), distance + 1); | ||
branchGradient(packetSource(packet), distance + 1); | ||
} | ||
|
||
void resetSelf() { | ||
setBlack(); | ||
shortestDistance = U32_MAX; | ||
} | ||
|
||
void handleReset( u8 * packet) { | ||
resetSelf(); | ||
branchReset(packetSource(packet)); | ||
} | ||
|
||
void stealGradient( ) { | ||
println("r"); | ||
delay(500); | ||
resetSelf(); | ||
setRed(); | ||
branch(0,1); | ||
branchGradient(0,1); | ||
} | ||
|
||
void setup() { | ||
Body.reflex('g', setGradient); | ||
resetSelf(); | ||
Body.reflex('g', handleGradient); | ||
Body.reflex('r', handleReset); | ||
} | ||
|
||
void loop() { | ||
if (buttonDown()) { | ||
stealGradient(); | ||
} | ||
if (buttonDown()) { | ||
stealGradient(); | ||
} | ||
} |