Source

blinksk / blinksk.cpp

The default branch has multiple heads

/**
 * Copyright (C) 2011 uniqx
 *  Metalab, 1010 Vienna, Austria
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/


#include <WProgram.h>

// data pins
#define D00 2
#define D01 3
#define D02 4
#define D03 5
#define D04 6
#define D05 7

#define DMIN 2 // lowest data pin number
#define DMAX 7 // highest data pin number
#define DCNT 6 // count of data pins

#define EP 13 // enable pin

// see http://arduino.cc/en/Reference/PortManipulation for
// detailed information about adreesing output registers
// directly.
#define LIGHT_OFF PORTB &= B11011111
#define LIGHT_ON  PORTB |= B00100000
#define SET_LIGHT(led_id) PORTD = ( led_id << 2 ) & ( PORTD | B11111100 )


// B0000 = 0x0    B1000 = 0x8
// B0001 = 0x1    B1001 = 0x9
// B0010 = 0x2    B1010 = 0xa
// B0011 = 0x3    B1011 = 0xb
// B0100 = 0x4    B1100 = 0xc
// B0101 = 0x5    B1101 = 0xd
// B0110 = 0x6    B1110 = 0xe
// B0111 = 0x7    B1111 = 0xf


// the first 4 int (8 byte .. 4 integer) address lights: 0..off 1..on
// the last int is the time for that image in milliseconds.
unsigned int anim[][5] = {

  {0x1000,0x0000,0x0000,0x0008,1000},
  {0x2000,0x0000,0x0000,0x0004,1000},
  {0x4000,0x0000,0x0000,0x0002,1000},
  {0x8000,0x0000,0x0000,0x0001,1000}

};
unsigned int anim_len=4;


void setup() {

  int i;
  for(i=DMIN;i<=DMAX;i++){
    pinMode(i, OUTPUT);
  }

  pinMode(EP, OUTPUT);

  Serial.begin(9600); // init serial

}

void loop() {

  int i, ii;

  /*for(ii=0;ii<128;ii++){
    for(i=0;i<64;i++){
      LIGHT_OFF;
      SET_LIGHT(i);
      LIGHT_ON;
    }
  }*/

  int pos;
  unsigned long anim_start_time;

  pos=0;
  anim_start_time = millis();

  while(pos < anim_len){

    for(ii=0;ii<4;ii++){
      for(i=0;i<16;i++){
        if( (anim[pos][ii] & (unsigned int)(1<<i) ) ) {
          LIGHT_ON;
          SET_LIGHT( (ii*16) + i);
          delay(0);
          LIGHT_OFF;
        }
      }
    }

    if( anim_start_time + anim[pos][4] < millis() ){
      pos++;
      anim_start_time = millis();
    }

  }

}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.