PWM abfragen Digital schalten

Hallo Uwe,

anei mal mein ganzer Code.
kannst du mir sagen was ich bei der analogwrite in der Zeile 85 und in der If in 86 anstatt der Fragezeichen einsetzen muß?

Da mir das ganze noch zu frisch ist komme ich nicht weiter.

#include <Wire.h>

#include <Button.h>
#include <DS1307.h>
#include <LiquidCrystal.h>
#define DS1307_ADDRESS 0x68 // This is the I2C address

// SainSmart LCD 16x2
LiquidCrystal lcd(8, 13, 9, 4, 5, 6);

// Arduino Mega 2560
const int Blue1Pin = 10;
const int White2Pin = 3;
//const int White3Pin = 7;
//const int White4Pin = 12;
const int Night1Pin = 2;
const unsigned long HOUR = 60 * 60;
const unsigned long MINUTE = 60;
const int TARGET_BRIGHTNESS = (255 * 3) / 4; // Target brightness is 3/4 of full

void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
Wire.begin();
}

byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}

void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("***");
lcd.setCursor(4,0);

///// Get time from RTC into RTCHour, RTCMinute, RTCSecond

// Set the register pointer to 0 (Second)
Wire.beginTransmission(DS1307_ADDRESS);
Wire.send((byte)0);
Wire.endTransmission();

// Read Second, Minute, and Hour
Wire.requestFrom(DS1307_ADDRESS, 3);

int RTCSecond = bcdToDec(Wire.receive());
int RTCMinute = bcdToDec(Wire.receive());
int RTCHour = bcdToDec(Wire.receive() & 0b111111); //24 hour time

// write Time to LCD XX:XX:XX
if(RTCHour < 10) {
lcd.print("0");
}
lcd.print(RTCHour);
Serial.println(" ");
Serial.print(RTCHour);
lcd.print(":");
Serial.print(":");
if(RTCMinute < 10) {
lcd.print("0");
}
lcd.print(RTCMinute);
lcd.print(":");
Serial.print(RTCMinute);
Serial.print(":");
if(RTCSecond < 10) {
lcd.print("0");
}
lcd.print(RTCSecond);
Serial.print(RTCSecond);
lcd.setCursor(13,0);
lcd.print("***");

unsigned long time = RTCHour * HOUR + RTCMinute * MINUTE + RTCSecond; // Time in seconds

// write value within the timeframe to PWM
analogWrite(Blue1Pin, brightness(time, 7HOUR+00MINUTE, 21HOUR+00MINUTE));
analogWrite(White2Pin, brightness(time, 8HOUR+30MINUTE, 19HOUR+30MINUTE));

// write actual value in % to LCD (max. 255 = 100%)
analogWrite(10,??);
if (??==0)
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
//Blue1Pin
lcd.setCursor(0,1);
lcd.print("Blue ");
if(((brightness(time, 7HOUR+00MINUTE, 21HOUR+00MINUTE))100/255) < 10) {
lcd.print("0");
}
lcd.print((brightness(time, 7
HOUR+00MINUTE, 21HOUR+00*MINUTE))*100/255);
lcd.print("%");

//White2Pin

lcd.setCursor(9,1);
lcd.print("Sun ");
if(((brightness(time, 8HOUR+30MINUTE, 19HOUR+30MINUTE))100/255) < 10) {
lcd.print("0");
}
lcd.print((brightness(time, 8
HOUR+30MINUTE, 19HOUR+30*MINUTE))*100/255);
lcd.print("%");
delay(1000);
}

byte brightness(unsigned long time, unsigned long fadeUpStart, unsigned long fadeDownStart)
{
// Mid day, light is at maximum brightness
if (time >= fadeUpStart + HOUR && time <= fadeDownStart)
return TARGET_BRIGHTNESS;

// Dawn: fade up the light
if (time >= fadeUpStart && time <= fadeUpStart + HOUR) // Fading up
{
unsigned long seconds = time - fadeUpStart; // Number of seconds into the fade time
return TARGET_BRIGHTNESS * seconds / (HOUR); // Fade up based on portion of interval completed.
}

// Evening: Fade down the light
if (time >= fadeDownStart && time <= fadeDownStart + HOUR) // Fading down
{
unsigned long seconds = (fadeDownStart + (HOUR)) - time; // Number of seconds remaining in the fade time
return TARGET_BRIGHTNESS * seconds / (HOUR); // Fade down based on portion of interval left.
}

// The remaining times are night and the lights is off
return 0; // Shouldn't get here
}

Hat eventuell jemand noch ein Codeschnipsel, damit ich mit zwei Tasten die Uhrzeit manuell verstellen kann??

Danke und Gruss

Bernd