MeggyJrDemo

From Noisebridge
(Difference between revisions)
Jump to: navigation, search
(New page: ===== Introduction ===== I built a [http://www.evilmadscientist.com/article.php/meggyjr Meggy Jr RGB] kit designed by Windell Oskay (Evil Mad Scientists Laboratory). ===== Standard Arduino...)
 
Line 13: Line 13:
 
===== Simplified Meggy API (part): =====
 
===== Simplified Meggy API (part): =====
 
<pre>
 
<pre>
  #include <MeggyJrSimple.h>
+
#include <MeggyJrSimple.h>
  
  EmptyScreen();      Turn off all LED
+
EmptyScreen();      Turn off all LED
  
  DrawPx(x,y,color);  Turn on LED (x=0~7, y=0~7, color=0~15)
+
DrawPx(x,y,color);  Turn on LED (x=0~7, y=0~7, color=0~15)
                                  ( x=0,y=0 is lower left )
+
                                ( x=0,y=0 is lower left )
  
  ShowScreen();      Copy buffer array to display video array
+
ShowScreen();      Copy buffer array to display video array
  
  SetAuxLEDs(N);      Set top LEDs: N=1:FarLeft, N=255:AllOn
+
SetAuxLEDs(N);      Set top LEDs: N=1:FarLeft, N=255:AllOn
  
  CheckButtonsDown()  Check which buttons currently pressed.
+
CheckButtonsDown()  Check which buttons currently pressed.
                      Sets six (global) variables:
+
                    Sets six (global) variables:
                        Button_A, Button_B, Button_Up,
+
                      Button_A, Button_B, Button_Up,
                        Button_Down, Button_Left, Button_Right
+
                      Button_Down, Button_Left, Button_Right
                      if (Button_Left || Button_Up ) ...
+
                    if (Button_Left || Button_Up ) ...
 
</pre>
 
</pre>
  
 
===== Regular Arduino calls still available: =====
 
===== Regular Arduino calls still available: =====
 
<pre>
 
<pre>
   delay(N);           Delay N msec.
+
   delay(N);         Delay N msec.
   long millis();     Current time in msec.
+
   millis();         Current time in msec.
   random(X);         Random number in [0,X)
+
   random(X);       Random number in [0,X)
 
</pre>
 
</pre>
  
Line 68: Line 68:
 
===== Program looping over frames w/o delay() =====
 
===== Program looping over frames w/o delay() =====
 
<pre>
 
<pre>
  unsigned long gLastTime;
+
unsigned long gLastTime;
  byte          gWhichDelay;
+
byte          gWhichDelay;
  int          gDelayMsec;
+
int          gDelayMsec;
  void setup() {
+
void setup() {
    MeggyJrSimpleSetup();
+
  MeggyJrSimpleSetup();
    gLastTime  = millis();
+
  gLastTime  = millis();
    gWhichDelay = 2;  // Waiting at: =1: first  delay(),
+
  gWhichDelay = 2;  // Waiting at: =1: first  delay(),
                      //            =2: second delay()
+
                    //            =2: second delay()
    gDelayMsec  = 500;
+
  gDelayMsec  = 500;
  }
+
}
  void loop() {
+
void loop() {
    if ( millis() > gLastTime + gDelayMsec ) {
+
  if ( millis() > gLastTime + gDelayMsec ) {
      if ( gWhichDelay == 1 ) {
+
    if ( gWhichDelay == 1 ) {
        DrawPx(7, 7, Dark);
+
      DrawPx(7, 7, Dark);
        ShowScreen();
+
      ShowScreen();
        gDelayMsec  = 500;
+
      gDelayMsec  = 500;
        gWhichDelay = 2;
+
      gWhichDelay = 2;
      }
+
    }
      else {
+
    else {
        DrawPx(7, 7, FullOn);
+
      DrawPx(7, 7, FullOn);
        ShowScreen();
+
      ShowScreen();
        gDelayMsec  = 100;
+
      gDelayMsec  = 100;
        gWhichDelay = 1;
+
      gWhichDelay = 1;
      }
+
      gLastTime = millis();
+
 
     }
 
     }
 +
    gLastTime = millis();
 
   }
 
   }
 +
}
 
</pre>
 
</pre>
 
===== References =====
 
===== References =====
 
* [http://www.evilmadscientist.com/article.php/meggyjr Meggy Jr Product Description -- http://www.evilmadscientist.com/article.php/meggyjr]
 
* [http://www.evilmadscientist.com/article.php/meggyjr Meggy Jr Product Description -- http://www.evilmadscientist.com/article.php/meggyjr]

Revision as of 15:46, 16 March 2009

Contents

Introduction

I built a Meggy Jr RGB kit designed by Windell Oskay (Evil Mad Scientists Laboratory).

Standard Arduino main program:
  int main(void) {
    setup();
    for (;;)
      loop();
    return 0;
  }
Simplified Meggy API (part):
#include <MeggyJrSimple.h>

EmptyScreen();      Turn off all LED

DrawPx(x,y,color);  Turn on LED (x=0~7, y=0~7, color=0~15)
                                ( x=0,y=0 is lower left )

ShowScreen();       Copy buffer array to display video array

SetAuxLEDs(N);      Set top LEDs: N=1:FarLeft, N=255:AllOn

CheckButtonsDown()  Check which buttons currently pressed.
                    Sets six (global) variables:
                      Button_A, Button_B, Button_Up,
                      Button_Down, Button_Left, Button_Right
                    if (Button_Left || Button_Up ) ...
Regular Arduino calls still available:
  delay(N);         Delay N msec.
  millis();         Current time in msec.
  random(X);        Random number in [0,X)
Colors for DrawPx():
  0 Dark
  1 Red       8 DimRed
  2 Orange    9 DimOrange
  3 Yellow   10 DimYellow
  4 Green    11 DimGreen
             12 DimAqua
  5 Blue     13 DimBlue    
  6 Violet   14 DimViolet
  7 White    15 FullOn
Looping with delay()
  void setup() {
    MeggyJrSimpleSetup();
  }
  void loop() {
    DrawPx(7, 7, FullOn);
    ShowScreen();
    delay(100);          // #1
    DrawPx(7, 7, Dark);
    ShowScreen();
    delay(500);          // #2
  }
Program looping over frames w/o delay()
unsigned long gLastTime;
byte          gWhichDelay;
int           gDelayMsec;
void setup() {
  MeggyJrSimpleSetup();
  gLastTime   = millis();
  gWhichDelay = 2;   // Waiting at: =1: first  delay(),
                     //             =2: second delay()
  gDelayMsec  = 500;
}
void loop() {
  if ( millis() > gLastTime + gDelayMsec ) {
    if ( gWhichDelay == 1 ) {
      DrawPx(7, 7, Dark);
      ShowScreen();
      gDelayMsec  = 500;
      gWhichDelay = 2;
    }
    else {
      DrawPx(7, 7, FullOn);
      ShowScreen();
      gDelayMsec  = 100;
      gWhichDelay = 1;
    }
    gLastTime = millis();
  }
}
References
Personal tools