Flashlight! – updated

DSC02359

My object is a flashlight that lights up when you squeeze (more you squeeze, brighter it gets). I decided to hack a flashlight and use the structure, led, and its lens inside.

DSC02324     DSC02325Battery pack cable soldered to the battery connection structure of flashlight.

DSC02327     DSC02333Arduino connected with led, and placed on a piece of laser-cut acrylic. LED/lens glued as well.

DSC02335     Parts of the flashlight.

DSC02340     DSC02341Top cover laser-cut and sowed on to the whole structure.

DSC02348

DSC02350      DSC02354

And here’s the sketch:

#include <Adafruit_NeoPixel.h>
const int analogInPin = A9; // Analog input pin that the potentiometer is attached to
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 6, NEO_GRB + NEO_KHZ800);
int sensorValue = 0; // value read from the pot

const int analogOutPin = 6;

int outputValue = 0;

void setup() {
Serial.begin(9600);
pinMode(9, INPUT_PULLUP); 
strip.begin();
strip.show();
}

void loop() {
sensorValue = analogRead(analogInPin);

if (sensorValue > 101){
analogWrite(analogOutPin, 0);
}
if (sensorValue < 100){
analogWrite(analogOutPin, 10);
}
if (sensorValue < 95){
analogWrite(analogOutPin, 20);
}
if (sensorValue < 90){
analogWrite(analogOutPin, 30);
}
if (sensorValue < 85){
analogWrite(analogOutPin, 50);
}
if (sensorValue < 80){
analogWrite(analogOutPin, 75);
}

if (sensorValue < 75){

analogWrite(analogOutPin, 100);
}
if (sensorValue < 70){
analogWrite(analogOutPin, 125);
}
if (sensorValue < 65){
analogWrite(analogOutPin, 150);
}
if (sensorValue < 60){
analogWrite(analogOutPin, 180);
}
if (sensorValue < 55){
analogWrite(analogOutPin, 200);
}
if (sensorValue < 50){
analogWrite(analogOutPin, 220);
}
if (sensorValue < 45){
analogWrite(analogOutPin, 240);
}
if (sensorValue < 40){
analogWrite(analogOutPin, 255);
}

Serial.print(“sensor = “);
Serial.print(sensorValue);
Serial.print(“\t output = “);
Serial.println(outputValue);
delay(2);
}

void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}