uc_design1
Published © GPL3+

BLINK Hat

Want a hat that gives you the power to control the light sequence? Well, this hat lights up and changes with just the press of a button.

BeginnerProtip696
BLINK Hat

Things used in this project

Hardware components

Arduino LilyPad USB
Arduino LilyPad USB
×1
LilyPad Rainbow LED (6 Colors)
SparkFun LilyPad Rainbow LED (6 Colors)
×1
Sewable Conductive Thread
Sewable Conductive Thread
×1
LilyPad Button Board
SparkFun LilyPad Button Board
×1
Snap Button
Can get at any local craft store
×1
Metal rings
Can be metal rings used for jewelry making.
×6
Hat
×1
Battery, 3.7 V
Battery, 3.7 V
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Sewing Needle
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Schematics

Diagram

Code

Code

Arduino
int button = A4;
int first = 6;
int second = A8;
int third = A7;
int leds[] = {first, second, third};
int mode = 0;
bool buttonPressed = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(first, OUTPUT);
  pinMode(second, OUTPUT);
  pinMode(third, OUTPUT);
  pinMode(button, INPUT_PULLUP);
}

bool checkButton(){
  if(!digitalRead(button)){
    buttonPressed = true;
  }
}

void modeOne(int speed){
  for(int i = 0; i < 255; i += 3){
    analogWrite(first, i);
    analogWrite(second, (i + 255/3) % 255);
    analogWrite(third, (i + 255/3) % 255);
    checkButton();
    delay(speed);
  }
  for(int i = 255; i >= 0; i -= 3){
    analogWrite(first, i);
    analogWrite(second, (i + 255/3) % 255);
    analogWrite(third, (i + 255/3) % 255);
    checkButton();
    delay(speed);
  }
}

void modeTwo(int speed){
  // modulus(%) is your friend
  //so the count (i) keeps going up. but using % makes it loop
  for(int i = 0; i < 3; i++){
    digitalWrite(leds[i % 3], HIGH);
    digitalWrite(leds[(i + 1) % 3], LOW);
    digitalWrite(leds[(i + 2) % 3], LOW);
    checkButton();
    delay(speed);
  }
  for(int i = 1; i >= 1; i--){
    digitalWrite(leds[i % 3], HIGH);
    digitalWrite(leds[(i + 1) % 3], LOW);
    digitalWrite(leds[(i + 2) % 3], LOW);
    checkButton();
    delay(speed);
  }
}

int numberOfModes = 2;

void loop() {
  switch(mode){
    case 0:
      modeOne(20);
      break;
    case 1:
      modeTwo(200);
      break;
  }
  
  if(buttonPressed){
    mode = (mode + 1) % numberOfModes;
    buttonPressed = false;
  }

}

Credits

uc_design1

uc_design1

1 project • 0 followers

Comments