Random TM1638 fun

Hey everyone.

I was just messing around with my Mega, thought I would post some of my results.
Just simple stuff, learning the basics.

Is there a projects section of the forum i’m missing?

/*
Kelvyn Panici
Dec. 11, 2011
Simple LED Scroller v3
*/

#include <TM1638.h>
#define RED TM1638_COLOR_RED
#define GREEN TM1638_COLOR_GREEN

TM1638 display1(51, 52, 53);
//Clock -> Pin 52
//DIO -> Pin 51
//STB0 -> Pin 53

boolean decimalDisplay = 0;  //Toggles decimal scroller
boolean wordDisplay    = 0;  //Toggles display of word
boolean debugDisplay   = 0;  //Togles visual display of count
 
int count = 0;             //Keeps track of led position on display.
int myDelay1,myDelay2;     //Inbetween delay and end position delay respectively.
byte myColor, myDecimal;   //myDecimal used in switch to set decimal position.
boolean flag = 0;       //From right to left, flag=0.
char* wordSpace = "  PANICI ";  //Default word display
char* myWord; 
char* myScrollingWord;  //Word scrolled when button is held.
boolean button1State = 0;
boolean lastButton1State = 0;
boolean button1Toggle = 0;

boolean button2State = 0;
boolean lastButton2State = 0;
boolean button2Toggle = 0;

boolean button3State = 0;
boolean lastButton3State = 0;
boolean button3Toggle = 0;

boolean button4State = 0;
boolean lastButton4State = 0;
boolean button4Toggle = 0;

void setup(){
 display1.setupDisplay(true,7); 
}



void loop(){
  button1State = (display1.getButtons() == 0b00000001);
  button2State = (display1.getButtons() == 0b00000010);
  button3State = (display1.getButtons() == 0b00000100);
  button4State = (display1.getButtons() == 0b00001000);
  
  if ((button1State != lastButton1State)&&(button1State == HIGH)) {
    if (button1Toggle == 0)
      button1Toggle = 1;
    else
      button1Toggle = 0;
  }
  lastButton1State = button1State;
  
    if ((button2State != lastButton2State)&&(button2State == HIGH)) {
    if (button2Toggle == 0)
      button2Toggle = 1;
    else
      button2Toggle = 0;
  }
  lastButton2State = button2State;
  
    if ((button3State != lastButton3State)&&(button3State == HIGH)) {
    if (button3Toggle == 0)
      button3Toggle = 1;
    else
      button3Toggle = 0;
  }
  lastButton3State = button1State;
  
    if ((button4State != lastButton4State)&&(button4State == HIGH)) {
    if (button4Toggle == 0)
      button4Toggle = 1;
    else
      button4Toggle = 0;
  }
  lastButton4State = button1State;
  
                         //Button Controls
  if (button1Toggle==1){   //If first button is held.
    //myDelay1=50;
    //myDelay2=62.5;
    myDelay1=41;
    myDelay2=58.5;
    myColor=GREEN;
    myWord = myScrollingWord; 
  }
  else{                      //If no button is held, these settings are used.
    myDelay1=91;
    myDelay2=116;
    //myDelay1=100;
    //myDelay2=125;
    myColor=RED;
    myWord = wordSpace;
  }
  
  if (button2Toggle==1)
    decimalDisplay = 1;
  else{
    decimalDisplay = 0;
    display1.clearDisplay();
  }
    
  if (button3Toggle==1)
    wordDisplay = 1;
  else{
    wordDisplay = 0;
    display1.clearDisplay();
  }
    
  if (button4Toggle==1)
    debugDisplay = 1;
  else{
    debugDisplay = 0;
    display1.clearDisplay();
  }

  
  
  
  
  switch (count) { //Switch that matches count with bitwise decimal position.
    case 0:
      myDecimal=0b10000000;
      myScrollingWord = "'       ";
      //myScrollingWord = "o       ";
      break;
    case 1:
      myDecimal=0b01000000;
      myScrollingWord = " '      ";
      //myScrollingWord = " o      ";
      break;
    case 2:
      myDecimal=0b00100000;
      myScrollingWord = "  '     ";
      //myScrollingWord = "  o     ";
      break;
    case 3:
      myDecimal=0b00010000;
      myScrollingWord = "   '    ";
      //myScrollingWord = "   o    ";
      break;
    case 4:
      myDecimal=0b00001000;
      myScrollingWord = "    '   ";
      //myScrollingWord = "    o   ";
      break;
    case 5:
      myDecimal=0b00000100;
      myScrollingWord = "     '  ";
      //myScrollingWord = "     o  ";
      break;
    case 6:
      myDecimal=0b00000010;
      myScrollingWord = "      ' ";
      //myScrollingWord = "      o ";
      break;
    case 7:
      myDecimal=0b00000001;
      myScrollingWord = "       '";
      //myScrollingWord = "       o";
      break;
  }
  
  
  
  
       //Display modes. Controlled with constants at top of program.
  if (decimalDisplay==1 && wordDisplay==1){
    display1.setDisplayToString(myWord,myDecimal);
  }
  else{
  if (decimalDisplay==1)
    display1.setDisplayToString("        ",myDecimal);
  if (wordDisplay==1)
    display1.setDisplayToString(myWord);
  }
  if (debugDisplay==1)
    display1.setDisplayDigit(count,0,false);





  if (count==8){                //What to do when RH end of display is reached
     flag = 1;
     delay(myDelay2);
  }
     if (count==0){              //What to do when LH end of display is reached
     flag = 0;
     delay(myDelay2);
   }
   
   
   
   
             //LED scrolling control 
  if (count <= 7 && flag == 0){   //Moves from left to right
   display1.setLED(myColor, count);
   display1.setLED(0, count-1);
   delay(myDelay1);
   count++;
  }
  else{                            //Moves from right to left
   display1.setLED(0, count);
   display1.setLED(myColor,count-1);
   delay(myDelay1);
   count--;
  }
}

I also made a Christmas display. No video though. I’d like to make it autoupdate the days, maybe i’ll mess with it later today.

/*
Kelvyn Panici
Dec. 10, 2011
Christmas Countdown v1
*/

#include <TM1638.h>
#define RED TM1638_COLOR_RED
#define GREEN TM1638_COLOR_GREEN

TM1638 display1(51, 52, 53);
//Clock -> Pin 52
//DIO -> Pin 51
//STB0 -> Pin 53

void setup(){
  display1.setupDisplay(true,7);
  String myWords = " 14 days";
  display1.setDisplayToString(myWords);
}

void loop(){
    display1.setLED(RED, 0);
    display1.setLED(GREEN, 1);
    display1.setLED(RED, 2);
    display1.setLED(GREEN, 3);
    display1.setLED(RED, 4);
    display1.setLED(GREEN, 5);
    display1.setLED(RED, 6);
    display1.setLED(GREEN, 7);
    delay(500);
    display1.setLED(GREEN, 0);
    display1.setLED(RED, 1);
    display1.setLED(GREEN, 2);
    display1.setLED(RED, 3);
    display1.setLED(GREEN, 4);
    display1.setLED(RED, 5);
    display1.setLED(GREEN, 6);
    display1.setLED(RED, 7);
    delay(500);
}