Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/pgmspace.h> //AVR library for writing to ROM
- #include <Charliplexing.h> //Imports the library, which needs to be
- //Initialized in setup.
- //Sets the time each frame is shown (milliseconds)
- const unsigned int blinkdelay = 75;
- boolean fadeMode = false;
- byte brightness = 7; //Brightness goes from 0-7
- /*
- The BitMap array is what contains the frame data. Each line is one full frame.
- Since each number is 16 bits, we can easily fit all 14 LEDs per row into it.
- The number is calculated by adding up all the bits, starting with lowest on
- the left of each row. 18000 was chosen as the kill number, so make sure that
- is at the end of the matrix, or the program will continue to read into memory.
- Here PROGMEM is called, which stores the array into ROM, which leaves us
- with our RAM. You cannot change the array during run-time, only when you
- upload to the Arduino. You will need to pull it out of ROM, which is covered
- below. If you want it to stay in RAM, just delete PROGMEM
- */
- PROGMEM const uint16_t BitMap[][9] = {
- //smiley face moving across screen
- //1 2 3 4 5 6 7 8 9
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 1, 0, 0, 0, 0},
- {0, 0, 0, 0, 1, 0, 0, 0, 0},
- {0, 1, 1, 0, 3, 1, 1, 0, 0},
- {0, 1, 1, 0, 3, 1, 1, 0, 0},
- {0, 3, 3, 0, 6, 3, 3, 1, 0},
- {0, 3, 3, 0, 6, 3, 3, 1, 0},
- {0, 6, 6, 0, 12, 6, 7, 3, 1},
- {0, 6, 6, 0, 12, 6, 7, 3, 1},
- {0, 12, 12, 0, 24, 12, 14, 7, 3},
- {0, 12, 12, 0, 24, 12, 14, 7, 3},
- {0, 24, 24, 0, 48, 24, 29, 15, 7},
- {0, 24, 24, 0, 48, 24, 29, 15, 7},
- {0, 49, 49, 0, 96, 49, 59, 31, 14},
- {0, 49, 49, 0, 96, 49, 59, 31, 14},
- {0, 99, 99, 0, 193, 99, 119, 62, 28},
- {0, 99, 99, 0, 193, 99, 119, 62, 28},
- {0, 198, 198, 0, 387, 198, 238, 124, 56},
- {0, 198, 198, 0, 387, 198, 238, 124, 56},
- {0, 396, 396, 0, 774, 396, 476, 248, 112},
- {0, 396, 396, 0, 774, 396, 476, 248, 112},
- {0, 792, 792, 0, 1548, 792, 952, 496, 224},
- {0, 792, 792, 0, 1548, 792, 952, 496, 224},
- {0, 1584, 1584, 0, 3096, 1584, 1904, 992, 448},
- {0, 1584, 1584, 0, 3096, 1584, 1904, 992, 448},
- {0, 3168, 3168, 0, 6192, 3168, 3808, 1984, 896},
- {0, 3168, 3168, 0, 6192, 3168, 3808, 1984, 896},
- {0, 6336, 6336, 0, 12384, 6336, 7616, 3968, 1792},
- {0, 6336, 6336, 0, 12384, 6336, 7616, 3968, 1792},
- {0, 12672, 12672, 0, 8384, 12672, 15232, 7936, 3584},
- {0, 12672, 12672, 0, 8384, 12672, 15232, 7936, 3584},
- {0, 8960, 8960, 0, 384, 8960, 14080, 15872, 7168},
- {0, 8960, 8960, 0, 384, 8960, 14080, 15872, 7168},
- {0, 1536, 1536, 0, 768, 1536, 11776, 15360, 14336},
- {0, 1536, 1536, 0, 768, 1536, 11776, 15360, 14336},
- {0, 3072, 3072, 0, 1536, 3072, 7168, 14336, 12288},
- {0, 3072, 3072, 0, 1536, 3072, 7168, 14336, 12288},
- {0, 6144, 6144, 0, 3072, 6144, 14336, 12288, 8192},
- {0, 6144, 6144, 0, 3072, 6144, 14336, 12288, 8192},
- {0, 12288, 12288, 0, 6144, 12288, 12288, 8192, 0},
- {0, 12288, 12288, 0, 6144, 12288, 12288, 8192, 0},
- {0, 8192, 8192, 0, 12288, 8192, 8192, 0, 0},
- {0, 8192, 8192, 0, 12288, 8192, 8192, 0, 0},
- {0, 0, 0, 0, 8192, 0, 0, 0, 0},
- {0, 0, 0, 0, 8192, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {18000}
- };
- void setup() {
- LedSign::Init(GRAYSCALE); //Initializes the screen
- }
- void loop() {
- if(fadeMode)
- for (uint8_t gray = 1; gray < SHADES; gray++)
- DisplayBitMap(gray); //Displays the bitmap
- else DisplayBitMap(brightness); //Displays the bitmap
- }
- void DisplayBitMap(uint8_t grayscale)
- {
- boolean run=true; //While this is true, the screen updates
- byte frame = 0; //Frame counter
- byte line = 0; //Row counter
- unsigned long data; //Temporary storage of the row data
- unsigned long start = 0;
- while(run == true) {
- for(line = 0; line < 9; line++) {
- //Here we fetch data from program memory with a pointer.
- data = pgm_read_word_near (&BitMap[frame][line]);
- //Kills the loop if the kill number is found
- if (data==18000){
- run=false;
- }
- //This is where the bit-shifting happens to pull out
- //each LED from a row. If the bit is 1, then the LED
- //is turned on, otherwise it is turned off.
- else for (byte led=0; led<14; ++led) {
- if (data & (1<<led)) {
- LedSign::Set(led, line, grayscale);
- }
- else {
- LedSign::Set(led, line, 0);
- }
- }
- }
- LedSign::Flip(true);
- unsigned long end = millis();
- unsigned long diff = end - start;
- if ( start && (diff < blinkdelay) )
- delay( blinkdelay - diff );
- start = end;
- frame++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement