Hey good day
I wanted to ask briefly because I am building a light box, and it works as followed:
A small solar board charges a small 2700mAh battery and this keeps an Arduino Nano alive. This is woken up from sleep mode by a photoresistor. After that, the PIR registers a movement and there is a pulsating LED. Now I have built a working code for simple LED strips via PWM. Now I would like to use Pixel LED, but I can't get this code to work ... Maybe you can help me.
This is the working PWM code (only the Serial print is doing his job a bit ugly, so it rows up AwAwAw and not fully spelling Awake if someone know how to solve this)
#include <Sleep_n0m1.h>
Sleep sleep;
#define intPin 2
const unsigned int ledPin = 10;
const unsigned int ledPin2 = 11;
boolean active = false; //Zwischenvariable
int pin = 3; // Datenpin festlegen
int movement = 0;
void setup()//Hier beginnt das Setup.
{
Serial.begin(9600); // Serialmonitor
pinMode (ledPin, OUTPUT); //LED PIN
pinMode(pin, INPUT); // Data PIR
CLKPR = 0x80; // (1000 0000) enable change in clock frequency
CLKPR = 0x03; // (0000 0001) use clock division factor 2 to reduce the frequency from 16 MHz to 8 MHz
}
void loop()
{
{
movement = digitalRead(pin); // Sensor auslesen
if(movement == HIGH && active == false){
active = true;
Serial.println("Bewegung erkannt");
}
// keine Bewegung nachdem eine Bewegung erkannt wurde
if(movement == LOW && active == true){
active = false;
Serial.println("Keine Bewegung");
}
if (movement == HIGH ) //Wenn der PIR Bewegung erkennt
{
for (int fadeValue = 25 ; fadeValue <= 220; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
analogWrite(ledPin2, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(15);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 220 ; fadeValue >= 25; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(15);
}
}
else //andernfalls…
{
analogWrite(ledPin2, 0);
analogWrite(ledPin, 0);
}
delay (50);//Eine kurze Pause, in der die LED an oder aus ist
}
delay(100); ////delays are just for serial print, without serial they can be removed
Serial.println("awk");
Serial.print("Sleeping");
delay(100); //delay to allow serial to fully print before sleep
sleep.pwrDownMode(); //set sleep mode
//Sleep till interrupt pin equals a particular state.
//In this case "low" is state 0.
sleep.sleepPinInterrupt(intPin,LOW); //(interrupt Pin Number, interrupt State)
}
That's the try-out for the PixelLeds and still not working (it's up loadable but hanging its self and won't work with the sleep mode);
#include <Sleep_n0m1.h>
#include <Adafruit_NeoPixel.h>
Sleep sleep;
#define intPin 2
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(19, PIN, NEO_GRB + NEO_KHZ800);
boolean active = false; //Zwischenvariable
int pin = 3; // Datenpin festlegen
int movement = 0;
void setup()//Hier beginnt das Setup.
{
Serial.begin(9600); // Serialmonitor
strip.begin();
strip.setBrightness(85); // Lower brightness and save eyeballs!
strip.show(); // Initialize all pixels to 'off'
pinMode(pin, INPUT); // Data PIR
CLKPR = 0x80; // (1000 0000) enable change in clock frequency
CLKPR = 0x03; // (0000 0001) use clock division factor 2 to reduce the frequency from 16 MHz to 8 MHz
}
void loop()
{
{
movement = digitalRead(pin); // Sensor auslesen
if(movement == HIGH && active == false){
active = true;
Serial.println("Bewegung erkannt");
}
// keine Bewegung nachdem eine Bewegung erkannt wurde
if(movement == LOW && active == true){
active = false;
Serial.println("Keine Bewegung");
}
if (movement == HIGH ) //Wenn der PIR Bewegung erkennt
{
int TOTAL_LEDS = 60;
float MaximumBrightness = 255;
float SpeedFactor = 0.008; // I don't actually know what would look good
float StepDelay = 5; // ms for a step delay on the lights
// Make the lights breathe
for (int i = 0; i < 65535; i++) {
// Intensity will go from 10 - MaximumBrightness in a "breathing" manner
float intensity = MaximumBrightness /2.0 * (1.0 + sin(SpeedFactor * i));
strip.setBrightness(intensity);
// Now set every LED to that color
for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {
strip.setPixelColor(ledNumber, 255, 0, 200);
}
strip.show();
//Wait a bit before continuing to breathe
delay(StepDelay);
}
}
else //andernfalls…
{
strip.clear();
}
delay (50);//Eine kurze Pause, in der die LED an oder aus ist
}
delay(100); ////delays are just for serial print, without serial they can be removed
Serial.println("awk");
Serial.print("Sleeping");
delay(100); //delay to allow serial to fully print before sleep
sleep.pwrDownMode(); //set sleep mode
//Sleep till interrupt pin equals a particular state.
//In this case "low" is state 0.
sleep.sleepPinInterrupt(intPin,LOW); //(interrupt Pin Number, interrupt State)
}
Looking forward for help, and here are some pictures of the PWM version of it: