noiasca:
ach der noiasca hat die Klammer beim Funktionsaufruf vergessen und der Tim schreibt das falsch ab und achtet nicht auf die Kompilermeldungen.
if (isDark())
So vieleicht:
// Lighthouse with 8 LEDs and one top PWM
// https://forum.arduino.cc/index.php?topic=711838
// by noiasca
// 2020-11-03 V2: LDR
define DEBUG_UART 1
const uint8_t pwmPin = 3; // UNO PWM pins 3, 5, 6, 9, 10, 11
const uint8_t ledPin[] = {2, 4, 5, 6, 7, 8, 9, 10}; // Pins simulating a "running light"
const size_t totalNoLeds = sizeof(ledPin);
const uint8_t sensorPin = A1; // LDR for day/night/
const uint8_t adcDark = 30; // threashold LDR for dark/night
const uint8_t adcBright = 100; // threashold LDR for bright/day
uint32_t currentMillis = 0; // stores actual timestamp
bool isDark (void)
{
static bool result = false;
int sensorValue = analogRead(sensorPin);
if (sensorValue < adcDark) result = true;
else if (sensorValue > adcBright) result = false;
return result;
}
void doRunning() // switch on / off one LED after the other
{
static uint8_t actual = totalNoLeds - 1; // start with the last LED
static uint32_t previousMillis = 0; // stores timestamp/millis of last change
const uint8_t myInterval = 5; // interval in seconds
if (isDark())
{
if DEBUG_UART
Serial.println("dark/night");
endif
if (currentMillis - previousMillis >= myInterval * 1000UL)
{
previousMillis = currentMillis;
digitalWrite(ledPin[actual], LOW); // switch off old (=current) LED
actual++; // goto next LED
if (actual >= totalNoLeds) actual = 0; // handle rollover to zero
digitalWrite(ledPin[actual], HIGH); // switch on new LED
if DEBUG_UART
Serial.print("actual Pin=");
Serial.println(ledPin[actual]);
endif
}
}
else
{
if DEBUG_UART
Serial.println("bright/day"); // if day and pin is on switch pin off
endif
if (digitalRead(ledPin[actual]) == HIGH)
digitalWrite(ledPin[actual], LOW);
}
}
void doPWM() // Pulse/fade the LED up and down
{
static uint32_t previousMillis = 0; // stores timestamp/millis of last change
const uint16_t myInterval = 10; // speed of PWM
static int8_t dir = 1; // direction upwards(1) or downwards (-1)
static uint8_t newPwm;
if (millis() - previousMillis >= myInterval)
{
previousMillis = millis();
if (dir == 1 && newPwm >= 254) // end of scale
dir = -1; // go downwards
if (dir == -1 && newPwm <= 54) // lower end of pwm scale
dir = 1; // go upwards
newPwm += dir; // this will increase (+1) or decrease (-1) the PWM
analogWrite(pwmPin, newPwm);
if DEBUG_UART
Serial.print("newPwm=");
Serial.println(newPwm);
endif
}
}
void setup() {
if DEBUG_UART
Serial.begin(115200);
endif
for (uint8_t i = 0; i < totalNoLeds; i++) {
pinMode(ledPin[i], OUTPUT);
}
pinMode(pwmPin, OUTPUT);
}
void loop() {
currentMillis = millis();
doPWM(); // check, if PWM needs to be changed
doRunning(); // check, if one of the running LEDs need to be changed
// do what ever you want unblocked here
}
Ich hab es so gemacht :) ging dann auch
bool isDark = false;
void doDS(){
if (analogRead(eingang) < Nacht){
isDark = true;
}
else if (analogRead(eingang) > Tag) isDark = false;
}
void doRunning()
{
static uint8_t actual = totalNoLeds - 1;
static uint32_t previousMillis = 0;
const uint8_t myIntervall = 2; // Schenlligkeit Fenster in Sekunden
sensorWert= analogRead(eingang);
Serial.print ("Helligkeit= ");
Serial.println (sensorWert);
if (isDark){
if (currentMillis - previousMillis >= myIntervall * 1000UL)
{
previousMillis = currentMillis;
digitalWrite(ledPin[actual], LOW);
actual++;
if (actual >= totalNoLeds) actual = 0;
digitalWrite(ledPin[actual], HIGH);