/* Arduino Kurs FES Juli 2017 * Programm 8b: Verbesserter LED-Dimmer */ // Tabelle mit logarithmischen PWM-Werten für gleichmässige Leuchtabstufung int duty_cycle_table[31] = {0, 1, 2, 3, 5, 8, 12, 15, 20, 25, 30, 36, 43, 50, 58, 66, 75, 84, 94, 104, 115, 127, 139, 152, 165, 178, 193, 208, 223, 239, 255}; /* I/O Pins */ int button_low = 12; int button_high = 11; int led_pin = 3; int light_level = 15; void setup() { pinMode(button_low, INPUT_PULLUP); pinMode(button_high, INPUT_PULLUP); } void loop() { if (digitalRead(button_low) == LOW) { // wenn button_low gedrückt ist, ... if (light_level > 0) // ... light_level verkleinern --light_level; }; if (digitalRead(button_high) == LOW) { // wenn button_high gedrückt ist, ... if (light_level < 30) // light_level vergrössern ++light_level; }; analogWrite(led_pin, duty_cycle_table[light_level]); // duty_cycle setzen delay(100); // einen Moment warten }