#ifndef SHIELD_MULTIFUNCTION_H
#define SHIELD_MULTIFUNCTION_H

#include <Arduino.h>
#include "KK_ButtonHandler.h"

class Shield_MultiFunction {
  public:
    Shield_MultiFunction();
    
    void begin();
    void update(); // Muss im loop() aufgerufen werden

    // --- Die 3 Taster (direkt als KK_ButtonHandler Objekte) ---
    KK_ButtonHandler btn1;
    KK_ButtonHandler btn2;
    KK_ButtonHandler btn3;

    // --- LEDs (D1=13, D2=12, D3=11, D4=10) ---
    void setLED(uint8_t ledNum, bool state);
    void setLEDPWM(uint8_t ledNum, uint8_t value); // Nur für D3 (11) und D4 (10)

    // --- Summer (Buzzer an Pin 3) ---
    void setBuzzer(bool state);
    void playTone(uint16_t freq, uint32_t ms);

    // --- Poti (A0) ---
    uint16_t readPoti();

    // --- 4x7 Segment Display (Latch=4, Clk=7, Data=8) ---
    void showNumber(int num);
    void showWord(char c1, char c2, char c3, char c4);
    void clearDisplay();

  private:
    uint8_t _displayMemory[4]; 
    unsigned long _lastDisplayUpdate;
    uint8_t _currentDigit;
    
    // Timer für den Buzzer
    unsigned long _buzzerTurnOffTime;
    bool _buzzerToneActive;

    void _writeDigit(uint8_t digit, uint8_t value);
    uint8_t _charToSegment(char c);
    
    // Pin Definitionen
    const int _latchPin = 4;
    const int _clkPin = 7;
    const int _dataPin = 8;
    const int _buzzerPin = 3;
};

#endif