Knåpar på en ficklampa. Med.
Lite kod.
Kod: Markera allt
// Ficklampa
#include <Adafruit_NeoPixel.h>
#define PIN 0
#define STRIPSIZE 1
// Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIPSIZE, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(55); // Lower to 25 brightness and save eyeballs!
strip.show(); // Initialize all pixels to 'off'
int led = 1; // 13 = uno 1 = attiny
pinMode(led, OUTPUT); pinMode(5, INPUT); pinMode(4, OUTPUT);
// const int analogInPin = 0; // Analog input pin 5= uno 0 = pin5 digistump
// int sensorValue = 0; // value read from the pot
// Serial.begin(9600);
}
void loop() {
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to
int led = 1; // 13 = uno 1 = attiny
const int analogInPin = 0; // Analog input pin 5= uno 0 = pin5 digistump
//sensorValue = analogRead(0); //Read P5 //To set to input: pinMode(5, INPUT);
// P5 is analog input 0, so when you are using analog read, you refer to it as 0.
lvit: // låg vit
digitalWrite(led, HIGH); digitalWrite(4, HIGH);
// sensorValue = analogRead(0);
outputValue = map(sensorValue, 0, 1023, 0, 255);
colorWipe(strip.Color(100,100,100), 25); // White not max
if (sensorValue < 150) {digitalWrite(led, HIGH); delay( 2500); goto mvit; }
// Serial.print(sensorValue); Serial.println(" lvit");
delay(500);
goto lvit;
mvit:
digitalWrite(led, LOW);
sensorValue = analogRead(analogInPin);
colorWipe(strip.Color(sensorValue,0,0), 25); // White not max
if (sensorValue > 150) {digitalWrite(led, LOW); delay(2500); goto hvit; }
// Serial.print(sensorValue); Serial.println(" mvit");
delay(500);
goto mvit;
hvit:
digitalWrite(led, HIGH);
sensorValue = analogRead(analogInPin);
colorWipe(strip.Color(0,sensorValue,0), 25); // White not max
if (sensorValue > 150) {digitalWrite(led, HIGH); delay(2500); goto roed;}
// Serial.print(sensorValue); Serial.println(" hvit");
delay(500);
goto hvit;
roed:
digitalWrite(led, LOW);
sensorValue = analogRead(analogInPin);
colorWipe(strip.Color(0,0,sensorValue), 25); // Red
// Serial.print(sensorValue); Serial.println(" red");
delay(2500);
// colorWipe(strip.Color(0, 64, 0), 100); // Green
// delay(2500);
// colorWipe(strip.Color(0, 0, 64), 100); // Blue
// delay(2500);
}
// Fill the dots one after the other with a color
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);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
Funkar inte helt. Lite moddad version funkar på min Arduino UNO. Jag har inte lärt mig serial debug på digisparken. Så jag ser inte hur analog in jobbar.
Det kommer att bli fler funktioner. Den drivs nu med en batteribankficklampa

. Men jag bygger nog in den i en gammal ficklampa. Med 18650 batteri och USB laddkontroller.
Om det behövs av platsskäl, blir det liknande en.
[img]http://www.höglandskompaniet.se/public/img/user/403.jpg[/img]
Funktioner:
* Vitt ljus i olika styrkor
* Olika färger
* Pulsning för energispar och skicka div koder
* Div givare tex temp ljus tilt kompass m.m
Fyll gärna på med fler.