NataliaaaaaaaaAbraham Contreras
Published

Snowflake Ornament

Cute snowflake-shaped ornament with programmable LED sequence.

BeginnerWork in progress1 hour706

Things used in this project

Hardware components

ATTINY13
×1
Resistor 0805 220 ohm
×3
LED 0805
×6
Battery holder for CR2012 or similar
×1
Capacitor 0805 0.1uF
×1
Slide swich SMD
×1
JLCPCB Customized PCB
JLCPCB Customized PCB
×1

Software apps and online services

Arduino IDE
Arduino IDE
Atmel Studio 7

Story

Read more

Custom parts and enclosures

Kicad project

Schematics

Schematics

Code

Arduino sketch

C/C++
/********************************************************* 
 This sketch demonstrates the use of a watchdog timer.
 The watchdog timer causes a processor reset to occur if
 it is allowed to time out. When the sketch is running
 inside the second while loop, the watch dog timer is
 consistently reset to prevent a timeout. When PB0 is 
 pulled high, it breaks out of the while loop and causes 
 the watch dog timer to reset the processor.
 ********************************************************/ 

#include <avr/io.h>
#include <util/delay.h>
#include <avr/wdt.h>

// Variable to store the counted value (uint16_t = unsigned int)
uint16_t counter = 0;

#define CHARLIE_A 0
#define CHARLIE_B 1
#define CHARLIE_C 2
byte randomLed = 0;

void setup ()
 {
// resetWatchdog ();  // do this first in case WDT fires
 pinMode(3, INPUT_PULLUP);
 pinMode(4, INPUT_PULLUP);
 pinMode(5, INPUT_PULLUP);
 pinMode(CHARLIE_A, OUTPUT);
 pinMode(CHARLIE_B, OUTPUT);
 pinMode(CHARLIE_C, OUTPUT);
// ADCSRA |= (1<<ADEN); //Enable ADC
 //randomSeed (analogRead (0));    // randomize
 ADCSRA &= ~(1<<ADEN); //Disable ADC, saves ~230uA
 }  // end of setup

void loop()
{
 
  //randomLed = random (1,7);  
  for (int i=0;i<=7;i++)
  {
   randomLEDs(i);
   wdt_enable(WDTO_1S); // Enable WDT with 1 second timeout
   _delay_ms(200);
   wdt_reset(); // 
  }

}


 void randomLEDs(int n)
{
//    pinMode(CHARLIE_A, OUTPUT); 
//    digitalWrite(CHARLIE_A, LOW);
//    pinMode(CHARLIE_B, OUTPUT); 
//    digitalWrite(CHARLIE_B, LOW);
//    pinMode(CHARLIE_C, OUTPUT); 
//    digitalWrite(CHARLIE_C, LOW);
//    
//
//    if(n==lastLED)
//    {
//      n = random(0, lastLED-1);
//    }
  switch(n)
   {
    case 1 :
       
       // LIGHT 1 
      //turn on LED L1
      pinMode(CHARLIE_A, OUTPUT);     //row 1
      digitalWrite(CHARLIE_A, LOW);
      pinMode(CHARLIE_B, OUTPUT);     //row 2
      digitalWrite(CHARLIE_B, HIGH);  
      pinMode(CHARLIE_C, INPUT);      //row 3
      digitalWrite(CHARLIE_C, LOW);
      
    break;
    case 2 :
    // LIGHT 2 
    //turn on LED L2
    pinMode(CHARLIE_A, OUTPUT);     //row 1
    digitalWrite(CHARLIE_A, HIGH);
    pinMode(CHARLIE_B, OUTPUT);     //row 2
    digitalWrite(CHARLIE_B, LOW);   
    pinMode(CHARLIE_C, INPUT);      //row 3
    digitalWrite(CHARLIE_C, LOW);
    
    break;
    case 3:
    // LIGHT 3
    pinMode(CHARLIE_A, INPUT);      //row 1
    digitalWrite(CHARLIE_A, LOW);
    pinMode(CHARLIE_B, OUTPUT);     //row 2
    digitalWrite(CHARLIE_B, LOW);  
    pinMode(CHARLIE_C, OUTPUT);     //row 3
    digitalWrite(CHARLIE_C, HIGH);
    
    break;
    case 4:
    // LIGHT 4 
    pinMode(CHARLIE_A, INPUT);     //row 1
    digitalWrite(CHARLIE_A, LOW);
    pinMode(CHARLIE_B, OUTPUT);    //row 2
    digitalWrite(CHARLIE_B, HIGH);  
    pinMode(CHARLIE_C, OUTPUT);    //row 3
    digitalWrite(CHARLIE_C, LOW);

    break;
    case 5:
    // LIGHT 5 
    pinMode(CHARLIE_A, OUTPUT);    //row 1
    digitalWrite(CHARLIE_A, LOW);
    pinMode(CHARLIE_B, INPUT);     //row 2
    digitalWrite(CHARLIE_B, LOW);
    pinMode(CHARLIE_C, OUTPUT);    //row3
    digitalWrite(CHARLIE_C, HIGH);
    
    break;
    case 6:
    // LIGHT 6 
    pinMode(CHARLIE_A, OUTPUT);
    digitalWrite(CHARLIE_A, HIGH);
    pinMode(CHARLIE_B, INPUT);
    digitalWrite(CHARLIE_B, LOW);
    pinMode(CHARLIE_C, OUTPUT);
    digitalWrite(CHARLIE_C, LOW);
    
    break;
//    default:
//     pinMode(CHARLIE_A, INPUT); 
//     pinMode(CHARLIE_B, INPUT); 
//     pinMode(CHARLIE_C, INPUT); 
   }

   //lastLED = n;
}

Credits

Nataliaaaaaaaa

Nataliaaaaaaaa

32 projects • 47 followers
i like cute electronic projects.
Abraham Contreras

Abraham Contreras

22 projects • 26 followers
Applications engineer and model scale maker

Comments