Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Valentine's Day Heart Shaped PCB
- // Uses an ATTiny45 at 1MHz to Charlieplex 20 LED's
- // Design and program by Brian Schulteis 2013
- // www.neonsquirt.com
- // Using the 5 lowest bits of PORT B
- // I use binary in the array below because it's
- // really clear which bits are set to what.
- const byte portInOrOut[] = { // 20 LEDs, 10 different pinModes to get them lit
- B00000011, B00000110, B00001100, B00011000, B00000101,
- B00001010, B00010100, B00001001, B00010010, B00010001
- };
- const byte portOnOrOff[] = { // 20 LEDs, 20 different states to get them lit
- B00000010, B00000001, B00000100, B00000010, B00001000,
- B00000100, B00010000, B00001000, B00000100, B00000001,
- B00001000, B00000010, B00010000, B00000100, B00001000,
- B00000001, B00010000, B00000010, B00010000, B00000001
- };
- // Each LED has a number, thes
- const byte sequenceA[] = {
- 1, 2, 4, 3, 9, 10, 15, 16, 19, 13, // Left Side Downward
- 20, 12, 19, 16, 14, 10, 9, 3, 4, 2, // Left Side Upward
- };
- const byte sequenceB[] = {
- 1, 5, 6, 7, 8, 11, 14, 17, 18, 12, // Right Side Downward
- 20, 13, 18, 17, 15, 11, 8, 7, 6, 5, // Right Side Upward
- };
- const byte sequenceC[] = {
- 10, 9, 15, 3, 16, 4, 19, 2, 13, 1, // Left to right
- 20, 5, 12, 6, 18, 7, 17, 8, 14, 11, 11 // or vice versa
- };
- const byte sequenceD[] = {
- 20, 13, 12, 19, 18, 16, 17, 15, 14, 10, // Up/down
- 11, 9, 8, 3, 7, 4, 6, 2, 5, 1 // or down/up
- };
- const byte sequenceE[] = {
- 1, 6, 8, 14, 18, 20, 19, 15, 9, 4, // Every other
- 5, 7, 11, 17, 12, 13, 16, 10, 3, 2
- };
- const byte sequenceF[] = {
- 1,5,6,7,8,11,14,17,18,12,20,13,19,16,15,10,9,3,4,2,1
- };
- const int speed=200; // int because it's quite likely I might increase this past 255
- byte i=0;
- unsigned long timeTrackerOne = 0;
- void setup() {
- // PUD Bit MCUCR Register - disable all pull-ups
- MCUCR |= 64; // Set the 6th bit HIGH
- }
- void lightLED(byte whichOne) {
- whichOne--; // Array starts at 0, LED numbering starts at 1.
- PORTB=0;
- DDRB = portInOrOut[whichOne/2]; // Sets pinModes (input or output)
- // the divide by 2 is because
- PORTB = portOnOrOff[whichOne]; // Set pinStates (HIGH or LOW)
- }
- void patternModeA() {
- // Two bulbs at a time
- for (int indexer=0; indexer < 20; indexer++) {
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- lightLED(sequenceA[indexer]); // Having two arrays of numbers
- lightLED(sequenceB[indexer]); // Made the counting simpler
- }
- PORTB=0;
- }
- }
- void patternModeB() {
- // First, we'll turn them all on from left to right
- for (byte l=0; l<20; l=l+2) { // work through the pattern to turn them all on.
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte r=0; r<=l; r++) { // We need this loop to keep them refreshed (on)
- lightLED(sequenceC[r]);
- }
- }
- }
- }
- void patternModeC() {
- // Next, we'll turn them all off from top to bottom
- for (byte l=20; l>0; l=l-2) { // work through the pattern to turn them all on.
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte r=0; r<=l; r++) { // We need this loop to keep them refreshed (on)
- lightLED(sequenceD[r]);
- }
- }
- }
- lightLED(20);
- delay(speed);
- PORTB=0;
- delay(speed);
- }
- void patternModeD() {
- // Next, we'll turn them all on from right to left
- PORTB=0;
- for (byte l=21; l>=1; l--) { // work through the pattern to turn them all on.
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte r=19; r>=l; r--) { // We need this loop to keep them refreshed (on)
- lightLED(sequenceC[r]);
- }
- }
- if (l>1) l--;
- }
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte r=0; r<19; r++) { // We need this loop to keep them refreshed (on)
- lightLED(r);
- }
- }
- }
- void patternModeE() {
- // Finally, we'll turn them all off from bottom to top
- for (byte l=0; l<20; l++) { // work through the pattern to turn them all on.
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte r=l; r<=20; r++) { // We need this loop to keep them refreshed (on)
- lightLED(sequenceD[r]);
- // if ((r<19) and (r>0)) {
- // lightLED(sequenceD[r+1]);
- // }
- }
- }
- if ((l<19) and (l>0)) l++;
- }
- }
- void patternModeF() { // Alternate Red or white
- for (byte r=0; r<20; r++) { // blink 20 times
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte l=0; l<10; l++) { // We need this loop to keep them refreshed (on)
- lightLED(sequenceE[l]);
- }
- }
- delay(speed/2);
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- for (byte l=10; l<20; l++) { // We need this loop to keep them refreshed (on)
- lightLED(sequenceE[l]);
- }
- }
- }
- }
- void patternModeG() { // Basic chaser mode
- for (int hi=0; hi<21; hi++) { // Start with a clockwise rotation
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- lightLED(sequenceF[hi]);
- }
- PORTB=0;
- }
- delay(speed*2);
- for (int hi=20; hi>=0; hi--) { // End with a CCW rotation
- timeTrackerOne=millis();
- while ((millis()-timeTrackerOne)<speed) {
- lightLED(sequenceF[hi]);
- }
- PORTB=0;
- }
- delay(speed*2);
- }
- void loop() {
- for (byte l=0; l<3; l++) { // 3 iterations of the up/down pattern
- patternModeA();
- }
- for (byte l=0; l<3; l++) { // 3 iterations of the chaser pattern
- patternModeG();
- }
- patternModeB(); // Start off, go left to right turning on
- patternModeC(); // Start on, go top to bottom turning off
- patternModeD(); // Start off, go right to left turn on
- patternModeE(); // Start on, go bottom to top turning off
- PORTB=0;
- delay(speed);
- patternModeF();
- PORTB=0;
- delay(speed);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement