hi there, i'm trying to make an alarmclock with some night (mood)lights.
clock is running fine, the neopixel ring lights up at the given time, but i can't get them off.
it is possible to set the lights to BLACK, but with this code the lights does not light up correctly.
so this is the code:
#include <Wire.h>
#include <Time.h>
#include <TimeLib.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
RTC_DS1307 RTC;
Adafruit_7segment disp = Adafruit_7segment();
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, 6, NEO_GRBW + NEO_KHZ800);
#define PIN 7
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(16, 7, NEO_GRBW + NEO_KHZ800);
#define resetPin1 9
const int inPin1 = 9; // Button 1
const int inPin2 = 10; // Button 2
const int ledPin1 = 6; // LED 1
const int ledPin2 = 7; // LED 2
int val = LOW;
void setup(){
Wire.begin();
RTC.begin();
/* if (! RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__, __TIME__));
}*/
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip2.begin();
strip2.show(); // Initialize all pixels to 'off'
pinMode(ledPin1, OUTPUT);
pinMode(inPin1, INPUT);
pinMode(ledPin2, OUTPUT);
pinMode(inPin2, INPUT);
disp.begin(0x70);
disp.setBrightness(1);
}
void loop() {
DateTime now = RTC.now();
tmElements_t tm;
disp.print(getDecimalTime());
disp.drawColon(true);
disp.writeDisplay();
delay(500);
disp.drawColon(false);
disp.writeDisplay();
delay(500);
if (now.hour() == 9 && now.minute() == 28){
GREEN();}
else {
val = digitalRead(inPin1);
if (val == HIGH){
RED();}
else {
digitalWrite(ledPin1,LOW);
digitalWrite(inPin1,HIGH);
}}
if ((now.hour() >= 6 && (now.hour() < 7)) && (now.minute() >= 25 && (now.minute() < 40))){
BLUE2();}
else {
val = digitalRead(inPin2);
if (val == HIGH){
RED2();}
else {
digitalWrite(ledPin2,LOW);}}}
int getDecimalTime(){
DateTime now = RTC.now();
int decimalTime = now.hour() * 100 + now.minute();
return decimalTime;}
// KLEUREN
void RED() {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255,0,0,0) );
strip.setBrightness(20);
strip.show();}}
void BLUE() {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0,0,255,0) );
strip.setBrightness(20);
strip.show();}}
void GREEN() {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0,255,0,0) );
strip.setBrightness(20);
strip.show();}}
void BLACK() {
strip.setBrightness(0);
strip.show();}
void GREEN2() {
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, strip2.Color(0,255,0,0) );
strip2.setBrightness(20);
strip2.show();}}
void BLUE2() {
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, strip2.Color(0,0,255,0) );
strip2.setBrightness(20);
strip2.show();}}
void RED2() {
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, strip2.Color(255,0,0,0) );
strip2.setBrightness(20);
strip2.show();}}
void BLACK2() {
strip2.setBrightness(0);
strip2.show();}
i'm using two on off (two pin) button for controlling the neopixel ring. With my code now, the lights go on, but when i set the button to -off- nothing happens... any help?
thx!