fix wrong modulo
This commit is contained in:
parent
2fed7bba77
commit
b36af62403
@ -1,20 +1,22 @@
|
||||
#include <WiFi.h>
|
||||
#include "time.h"
|
||||
#include <FastLED.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
#define MOD(a,b) ((((a)%(b))+(b))%(b))
|
||||
// LDR (GL5516 ) is connected to GPIO 34 (Analog ADC1_CH6
|
||||
// over a 56k voltage divider . Dark (0.5MOhm) , 10Lux (5-10kOhm)
|
||||
const int ldrPin = 34;
|
||||
// How many leds in your strip?
|
||||
#define NUM_LEDS 60
|
||||
#define BRIGHTNESS 30
|
||||
#define BRIGHTNESS 50
|
||||
#define COLOR_ORDER GRB
|
||||
#define DATA_PIN 5
|
||||
// Define the array of leds
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
|
||||
volatile int interruptCounter;
|
||||
volatile signed int interruptCounter;
|
||||
hw_timer_t * timer = NULL;
|
||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
@ -32,6 +34,7 @@ volatile int currentHour = 1;
|
||||
// variable for storing the potentiometer value
|
||||
volatile int ldrValue = 0;
|
||||
|
||||
WiFiManager wifiManager;
|
||||
const char* ssid = "koelner Gastzugang";
|
||||
const char* password = "deltaforce!";
|
||||
|
||||
@ -88,6 +91,7 @@ void setup()
|
||||
timerAttachInterrupt(timer, &onTimer, true);
|
||||
timerAlarmWrite(timer, 1000000, true);
|
||||
timerAlarmEnable(timer);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||
@ -96,7 +100,7 @@ void setup()
|
||||
FastLED.clear();
|
||||
|
||||
syncNTP();
|
||||
//currentSec = 40; currentMin = 1; currentHour=0;
|
||||
//currentSec = 40; currentMin = 1; currentHour = 2;
|
||||
}
|
||||
void LDR() {
|
||||
//brigthness measurement
|
||||
@ -105,23 +109,19 @@ void LDR() {
|
||||
FastLED.setBrightness( BRIGHTNESS );
|
||||
}
|
||||
else {
|
||||
FastLED.setBrightness( int(BRIGHTNESS - BRIGHTNESS / log(ldrValue)) ); //need some logarithm
|
||||
Serial.println("Brightness: " + String( int(BRIGHTNESS - BRIGHTNESS / log(ldrValue*10))));
|
||||
FastLED.setBrightness( int(BRIGHTNESS - BRIGHTNESS / log(ldrValue * 10)) );
|
||||
//Serial.println("Brightness: " + String( int(BRIGHTNESS - BRIGHTNESS / log(ldrValue * 10))));
|
||||
}
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
while (interruptCounter == 0) {
|
||||
delay(1);
|
||||
}
|
||||
if (interruptCounter > 0) {
|
||||
|
||||
portENTER_CRITICAL(&timerMux);
|
||||
interruptCounter--;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
currentSec--;
|
||||
}
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
|
||||
if (currentSec < 0) {
|
||||
currentSec = 59;
|
||||
@ -132,28 +132,37 @@ void loop()
|
||||
currentHour--;
|
||||
if (currentHour < 0) {
|
||||
currentHour = 11;
|
||||
timerAlarmDisable(timer);
|
||||
//timerAlarmDisable(timer);
|
||||
//ESP.restart();
|
||||
//syncNTP();
|
||||
timerAlarmEnable(timer);
|
||||
syncNTP();
|
||||
//timerAlarmEnable(timer);
|
||||
}
|
||||
}
|
||||
Serial.println("Ring Index: " + String(currentHour * 5) + ":" + String(currentMin) + ":" + String(currentSec));
|
||||
//Serial.println(String(interruptCounter) + " | Ring Index: " + String(currentHour * 5) + ":" + String(currentMin) + ":" + String(currentSec));
|
||||
}
|
||||
|
||||
//reset color
|
||||
leds[(currentSec + 1) % NUM_LEDS] = CRGB(30, 48, 40);
|
||||
leds[(currentMin + 1) % NUM_LEDS] = CRGB(30, 48, 40);
|
||||
//3 dots hour
|
||||
leds[(currentHour * 5 - 1) % NUM_LEDS] = CRGB::Gold;
|
||||
leds[(currentHour * 5) % NUM_LEDS] = CRGB::Gold;
|
||||
leds[(currentHour * 5 + 1) % NUM_LEDS] = CRGB::Gold;
|
||||
leds[((currentHour + 1) * 5 - 1) % NUM_LEDS] = CRGB(30, 48, 40);
|
||||
leds[((currentHour + 1) * 5 + 1) % NUM_LEDS] = CRGB(30, 48, 40);
|
||||
|
||||
//1 dot hour marking
|
||||
for (int dot = 0; dot < NUM_LEDS; dot++) {
|
||||
if (dot % 5 == 0) {
|
||||
leds[dot] = CRGB::OrangeRed;
|
||||
}
|
||||
}
|
||||
//3 dots hour
|
||||
if (currentHour == 0) {
|
||||
leds[59 % NUM_LEDS] = CRGB::Gold;
|
||||
}
|
||||
else {
|
||||
leds[(currentHour * 5 - 1) % NUM_LEDS] = CRGB::Gold;
|
||||
}
|
||||
leds[(currentHour * 5) % NUM_LEDS] = CRGB::Gold;
|
||||
leds[(currentHour * 5 + 1) % NUM_LEDS] = CRGB::Gold;
|
||||
|
||||
leds[0] = CRGB::Blue; //define high noon
|
||||
//leds[NUM_LEDS / 2] = CRGB::Green; //define half noon
|
||||
|
||||
@ -161,3 +170,4 @@ void loop()
|
||||
leds[(currentMin + 0) % NUM_LEDS] = CRGB::Orange;
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user