Primeira Parte #define OFF B11111111; #include #include #include #include #include static byte font[][8] PROGMEM = { { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000 }, { B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000000, B00000100 }, { B00001010, B00001010, B00001010, B00000000, B00000000, B00000000, B00000000, B00000000 }, { B00000000, B00001010, B00011111, B00001010, B00011111, B00001010, B00011111, B00001010 }, { B00000111, B00001100, B00010100, B00001100, B00000110, B00000101, B00000110, B00011100 }, { B00011001, B00011010, B00000010, B00000100, B00000100, B00001000, B00001011, B00010011 }, { B00000110, B00001010, B00010010, B00010100, B00001001, B00010110, B00010110, B00001001 }, { B00000100, B00000100, B00000100, B00000000, B00000000, B00000000, B00000000, B00000000 }, { B00000010, B00000100, B00001000, B00001000, B00001000, B00001000, B00000100, B00000010 }, { B00001000, B00000100, B00000010, B00000010, B00000010, B00000010, B00000100, B00001000 }, { B00010101, B00001110, B00011111, B00001110, B00010101, B00000000, B00000000, B00000000 }, { B00000000, B00000000, B00000100, B00000100, B00011111, B00000100, B00000100, B00000000 }, { B00000000, B00000000, B00000000, B00000000, B00000000, B00000110, B00000100, B00001000 }, { B00000000, B00000000, B00000000, B00000000, B00001110, B00000000, B00000000, B00000000 }, { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000100 }, { B00000001, B00000010, B00000010, B00000100, B00000100, B00001000, B00001000, B00010000 }, { B00001110, B00010001, B00010001, B00010011, B00010101, B00011001, B00010001, B00001110 }, { B00000100, B00001100, B00010100, B00000100, B00000100, B00000100, B00000100, B00011111 }, { B00001110, B00010001, B00010001, B00000010, B00000100, B00001000, B00010000, B00011111 }, { B00001110, B00010001, B00000001, B00001110, B00000001, B00000001, B00010001, B00001110 }, { B00010000, B00010000, B00010100, B00010100, B00011111, B00000100, B00000100, B00000100 }, { B00011111, B00010000, B00010000, B00011110, B00000001, B00000001, B00000001, B00011110 }, { B00000111, B00001000, B00010000, B00011110, B00010001, B00010001, B00010001, B00001110 }, { B00011111, B00000001, B00000001, B00000001, B00000010, B00000100, B00001000, B00010000 }, { B00001110, B00010001, B00010001, B00001110, B00010001, B00010001, B00010001, B00001110 }, { B00001111, B00010001, B00010001, B00001111, B00000001, B00000001, B00000001, B00000001 }, { B00000000, B00000100, B00000100, B00000000, B00000000, B00000100, B00000100, B00000000 }, { B00000000, B00000100, B00000100, B00000000, B00000000, B00000100, B00000100, B00001000 }, { B00000001, B00000010, B00000100, B00001000, B00001000, B00000100, B00000010, B00000001 }, { B00000000, B00000000, B00000000, B00011110, B00000000, B00011110, B00000000, B00000000 }, { B00010000, B00001000, B00000100, B00000010, B00000010, B00000100, B00001000, B00010000 }, { B00001110, B00010001, B00010001, B00000010, B00000100, B00000100, B00000000, B00000100 }, { B00001110, B00010001, B00010001, B00010101, B00010101, B00010001, B00010001, B00011110 }, { B00001110, B00010001, B00010001, B00010001, B00011111, B00010001, B00010001, B00010001 }, { B00011110, B00010001, B00010001, B00011110, B00010001, B00010001, B00010001, B00011110 }, { B00000110, B00001000, B00010000, B00010000, B00010000, B00010000, B00001000, B00000110 }, { B00011100, B00010010, B00010001, B00010001, B00010001, B00010001, B00010010, B00011100 }, { B00011111, B00010000, B00010000, B00011110, B00010000, B00010000, B00010000, B00011111 }, { B00011111, B00010000, B00010000, B00011110, B00010000, B00010000, B00010000, B00010000 }, { B00001110, B00010001, B00010000, B00010000, B00010111, B00010001, B00010001, B00001110 }, { B00010001, B00010001, B00010001, B00011111, B00010001, B00010001, B00010001, B00010001 }, { B00001110, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00001110 }, { B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00010100, B00001100 }, { B00010001, B00010010, B00010100, B00011000, B00011000, B00010100, B00010010, B00010001 }, { B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00011110 }, { B00010001, B00011011, B00011111, B00010101, B00010001, B00010001, B00010001, B00010001 }, { B00010001, B00011001, B00011001, B00010101, B00010101, B00010011, B00010011, B00010001 }, { B00001110, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001110 }, { B00011110, B00010001, B00010001, B00011110, B00010000, B00010000, B00010000, B00010000 }, { B00001110, B00010001, B00010001, B00010001, B00010001, B00010101, B00010011, B00001111 }, { B00011110, B00010001, B00010001, B00011110, B00011000, B00010100, B00010010, B00010001 }, { B00000111, B00001000, B00010000, B00001000, B00000100, B00000010, B00000010, B00011100 }, { B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100 }, { B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001110 }, { B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001010, B00000100 }, { B00010001, B00010001, B00010001, B00010001, B00010001, B00010101, B00010101, B00001010 }, { B00010001, B00011011, B00001010, B00000100, B00000100, B00001010, B00011011, B00010001 }, { B00010001, B00010001, B00001010, B00000100, B00000100, B00000100, B00000100, B00000100 }, { B00011111, B00000001, B00000010, B00000100, B00001000, B00010000, B00010000, B00011111 }, { B00001110, B00001000, B00001000, B00001000, B00001000, B00001000, B00001000, B00001110 }, { B00010000, B00001000, B00001000, B00000100, B00000100, B00000010, B00000010, B00000001 }, { B00001110, B00000010, B00000010, B00000010, B00000010, B00000010, B00000010, B00001110 }, { B00000100, B00001010, B00010001, B00000000, B00000000, B00000000, B00000000, B00000000 }, { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00011111 }, { B00001000, B00000100, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000 }, { B00000000, B00000000, B00000000, B00001110, B00010010, B00010010, B00010010, B00001111 }, { B00000000, B00010000, B00010000, B00010000, B00011100, B00010010, B00010010, B00011100 }, { B00000000, B00000000, B00000000, B00001110, B00010000, B00010000, B00010000, B00001110 }, { B00000000, B00000001, B00000001, B00000001, B00000111, B00001001, B00001001, B00000111 }, { B00000000, B00000000, B00000000, B00011100, B00010010, B00011110, B00010000, B00001110 }, { B00000000, B00000011, B00000100, B00000100, B00000110, B00000100, B00000100, B00000100 }, { B00000000, B00001110, B00001010, B00001010, B00001110, B00000010, B00000010, B00001100 }, { B00000000, B00010000, B00010000, B00010000, B00011100, B00010010, B00010010, B00010010 }, { B00000000, B00000000, B00000100, B00000000, B00000100, B00000100, B00000100, B00000100 }, { B00000000, B00000010, B00000000, B00000010, B00000010, B00000010, B00000010, B00001100 }, { B00000000, B00010000, B00010000, B00010100, B00011000, B00011000, B00010100, B00010000 }, { B00000000, B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00001100 }, { B00000000, B00000000, B00000000, B00001010, B00010101, B00010001, B00010001, B00010001 }, { B00000000, B00000000, B00000000, B00010100, B00011010, B00010010, B00010010, B00010010 }, { B00000000, B00000000, B00000000, B00001100, B00010010, B00010010, B00010010, B00001100 }, { B00000000, B00011100, B00010010, B00010010, B00011100, B00010000, B00010000, B00010000 }, { B00000000, B00001110, B00010010, B00010010, B00001110, B00000010, B00000010, B00000001 }, { B00000000, B00000000, B00000000, B00001010, B00001100, B00001000, B00001000, B00001000 }, { B00000000, B00000000, B00001110, B00010000, B00001000, B00000100, B00000010, B00011110 }, { B00000000, B00010000, B00010000, B00011100, B00010000, B00010000, B00010000, B00001100 }, { B00000000, B00000000, B00000000, B00010010, B00010010, B00010010, B00010010, B00001100 }, { B00000000, B00000000, B00000000, B00010001, B00010001, B00010001, B00001010, B00000100 }, { B00000000, B00000000, B00000000, B00010001, B00010001, B00010001, B00010101, B00001010 }, { B00000000, B00000000, B00000000, B00010001, B00001010, B00000100, B00001010, B00010001 }, Segunda Parte { B00000000, B00000000, B00010001, B00001010, B00000100, B00001000, B00001000, B00010000 }, { B00000000, B00000000, B00000000, B00011111, B00000010, B00000100, B00001000, B00011111 }, { B00000010, B00000100, B00000100, B00000100, B00001000, B00000100, B00000100, B00000010 }, { B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100 }, { B00001000, B00000100, B00000100, B00000100, B00000010, B00000100, B00000100, B00001000 }, { B00000000, B00000000, B00000000, B00001010, B00011110, B00010100, B00000000, B00000000 } }; int tMin, tHour, tSec, tDay, tMonth, tYear; char cMin, cHour, cSec, cDay, cMonth, cYear; char time[30]; //Pin connected to ST_CP (Latch) of 74HC595N byte latchPin = 8; ////Pin connected to DS (Data) of 74HC595 byte dataPin = 11; //Pin connected to SH_CP (clock) of 74HC595 byte clockPin = 12; uint8_t red[8], green[8], blue[8]; void setup() { Serial.begin(9600); RTC.stop(); RTC.set(DS1307_SEC,30); //set the seconds RTC.set(DS1307_MIN,34); //set the minutes RTC.set(DS1307_HR,9); //set the hours RTC.set(DS1307_DOW,6); //set the day of the week RTC.set(DS1307_DATE,11); //set the date RTC.set(DS1307_MTH,4); //set the month RTC.set(DS1307_YR,9); //set the year RTC.start(); //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); Timer1.initialize(10000); // initialize timer1 nad set interrupt period Timer1.attachInterrupt(screenUpdate); } void loop() { for (int i=1; i<8; i++) { getTime(); scrollLeft( time, 40, i); } } void screenUpdate() { uint8_t row = B00000001; for (byte k = 0; k < 9; k++) { digitalWrite(latchPin, LOW); // Open up the latch ready to receive data shiftOut(dataPin, clockPin, LSBFIRST, blue[k] ); // BLUE shiftOut(dataPin, clockPin, LSBFIRST, red[k] ); // RED shiftOut(dataPin, clockPin, LSBFIRST, green[k] ); // GREEN shiftOut(dataPin, clockPin, LSBFIRST, row ); digitalWrite(latchPin, HIGH); // Close the latch, sending the data in the registers out to the matrix row = row << 1; } } void scrollLeft(char myString[], int speed, byte colour) { if (colour>7) {return;} uint8_t firstChrRow, secondChrRow; uint8_t ledOutput, redOutput, greenOutput, blueOutput; byte chrPointer = 0; // Initialise the string position pointer byte Char1, Char2; byte scrollBit = 0; byte strLength = 0; unsigned long time; unsigned long counter; while (myString[strLength]) { /* Increment count till we reach the string */ strLength++;} counter = millis(); while (chrPointer < (strLength-1)) { time = millis(); if (time > (counter + speed)) { Char1 = myString[chrPointer]; Char2 = myString[chrPointer+1]; for (byte y= 0; y<8; y++) { firstChrRow = -(pgm_read_byte(&(font[Char1 - 32][y])))-1; secondChrRow = -(pgm_read_byte(&(font[Char2 - 32][y])))-1; ledOutput = (firstChrRow << scrollBit) | (secondChrRow >> (8 - scrollBit) ); byte ON = ledOutput; switch (colour) { case 1: redOutput = OFF; greenOutput = OFF; blueOutput = ON; break; case 2: redOutput = OFF; greenOutput = ON; blueOutput = OFF; break; case 3: redOutput = OFF; greenOutput = ON; blueOutput = ON; break; case 4: redOutput = ON; greenOutput = OFF; blueOutput = OFF; break; case 5: redOutput = ON; greenOutput = OFF; blueOutput = ON; break; case 6: redOutput = ON; greenOutput = ON; blueOutput = OFF; break; case 7: redOutput = ON; greenOutput = ON; blueOutput = ON; break; } red[y] = redOutput; green[y] = greenOutput; blue[y] = blueOutput; } scrollBit++; if (scrollBit > 7) { scrollBit = 0; chrPointer++; } counter = millis(); } } } void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut? //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1<