index : arduino-led-tube.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2017-03-14 4:29:15.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2017-03-14 4:29:15.0 +00:00:00
commit
a638a22dec6ca8982844d16017b86aafadfb01c2 [patch]
tree
d88d4981379a3e58f2b573cecbdc963f0dc68e4e
download
a638a22dec6ca8982844d16017b86aafadfb01c2.tar.gz

Initial commit.



Diff

 README.md    |   0
 led_tube.ino | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 108 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/led_tube.ino b/led_tube.ino
new file mode 100644
index 0000000..e56c210
--- /dev/null
+++ b/led_tube.ino
@@ -0,0 +1,108 @@
const int dataPin = 2;
const int clockPin = 4;
const int latchPin = 3;

unsigned char Digits[] = 
{// 0   1    2    3  4  5    6    7  8  9    A    b  C    d    E    F    -
  0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf
};
unsigned char DigitCells[4];

unsigned long previousMillis = 0;
const long interval = 1000;           

void setup() {
  // put your setup code here, to run once:
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

}

int max_minutes = 10;
int current_num = 0;

void loop() {

unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
      
      int seconds = current_num % 60;
      int minutes = current_num / 60;

      if (minutes > max_minutes)
      {
        current_num = 0;
        seconds = current_num % 60;
      }
      
      DigitCells[0] = seconds % 10;
      DigitCells[1] = seconds / 10 % 10;
      DigitCells[2] = minutes % 10;
      DigitCells[3] = minutes / 10 % 10;
    
      current_num++;

  }

      Display_Digits();
      
}

//http://edi.wang/post/2016/4/29/windows-10-iot-74hc595-led-digital-tube
void Display_Digits()
    {
      unsigned char *led_table;
      unsigned char i;
      
      led_table = Digits + DigitCells[0];
      i = *led_table;
      Digit_Write(i);     
      Digit_Write(0x01);    
      digitalWrite(latchPin,LOW);
      digitalWrite(latchPin,HIGH);

      led_table = Digits + DigitCells[1];
      i = *led_table;
      Digit_Write(i);   
      Digit_Write(0x02);    
      digitalWrite(latchPin,LOW);
      digitalWrite(latchPin,HIGH);
      
      led_table = Digits + DigitCells[2];
      i = *led_table;
      Digit_Write(i);     
      Digit_Write(0x04);  
      digitalWrite(latchPin,LOW);
      digitalWrite(latchPin,HIGH);
      

      led_table = Digits + DigitCells[3];
      i = *led_table;
      Digit_Write(i);     
      Digit_Write(0x08);    
      digitalWrite(latchPin,LOW);
      digitalWrite(latchPin,HIGH);
    }

    void Digit_Write(unsigned char X)
    {
      unsigned char i;
      for(i=8;i>=1;i--)
      {
        if (X&0x80) 
        {
          digitalWrite(dataPin,HIGH);
         }  
        else 
        {
          digitalWrite(dataPin,LOW);
        }
        X<<=1;
        digitalWrite(clockPin,LOW);
        digitalWrite(clockPin,HIGH);
      }
    }