Arnov Sharma
Published © MIT

Naruto Themed Night Lamp

Made a Naruto themed night lamp-based around ATtiny13A MCU and custom PCB.

BeginnerFull instructions provided4 hours528

Things used in this project

Hardware components

Microchip attiny13A
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

body

Lid

Schematics

sch

Code

code

C/C++
int switchPin = 4;     //4         
int led1Pin = 0;        //0

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by


int val;                        
int val2;                       
int buttonState;                
int Mode ; //= 0;              

void setup() 
{
pinMode(switchPin, INPUT_PULLUP);    
pinMode(led1Pin, OUTPUT);
buttonState = digitalRead(switchPin); 
}

void loop(){
 
      val = digitalRead(switchPin);      // read input value and store it in val
      delay(10);                         // 10 milliseconds is a good amount of time
      val2 = digitalRead(switchPin);     // read the input again to check for bounces
      
      if (val == val2) {                 // make sure we got 2 consistant readings!
        if (val != buttonState) {          // the button state has changed!
          if (val == HIGH) {                // check if the button is pressed
            if (Mode == 0) {         
              Mode = 1;               
            } else {
                if (Mode == 1) {       
                Mode = 2;           
            } else {
                if (Mode == 2) {     
                Mode = 3;           
            } else {
                if (Mode == 3) {     
                Mode = 0;  
           }
          }
         }
        }
       }
        }
          
        buttonState = val;                 // save the new state in our variable
      }

      // Now do whatever the lightMode indicates
      if (Mode == 0) {                       // FLIP FLOP
        digitalWrite(led1Pin, LOW);
      }

      if (Mode == 1) {
        analogWrite(led1Pin, brightness);
        brightness = brightness + fadeAmount;
        if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
      }

      if (Mode == 2) {
        digitalWrite(led1Pin, HIGH);
        delay(50);
        
      }
      if (Mode == 3) {
        analogWrite(led1Pin, 100);
        delay(50);
}
}

      
    

Credits

Arnov Sharma

Arnov Sharma

310 projects • 308 followers
Just your average MAKER

Comments