Jetzt wird alles super kompiliert.
Am Ende ist mein Ziel, dass eine LED in abhängigkeit vom Analogen Signal gedimmt wird. Das Signal wird über ein Potentiometer verändert. Also variiert das Signal von 0 V bis 5 V. Je nach Einstellung.
Leider leuchtet die LED beim Hochladen des Codes nur kurz auf und dann bleibt sie aus. Ist von der Code-Seite her alles korrekt?
double sensorPin = A0; // select the input pin for the potentiometer
double sensorValue = 0; // variable to store the value coming from the sensor
int dimled = 8; // pin led to dime
double a; // hilfsvariable berechnung
double b; // prozentualer wert von senorValue (100% = 50)
double Dauer;
void setup()
{
// declare the ledPin as an OUTPUT:
pinMode(dimled, OUTPUT);
}
void loop()
{
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
a = sensorValue * 10;
b = (100/50) * a; // prozent Anteil Einschaltdauer in Periode von 2 ms
Dauer = (b/100) * 2; // einschaltdauer in ms
digitalWrite(dimled, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(Dauer);
// turn the ledPin off:
digitalWrite(dimled, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(2-Dauer);
}