#define potPin A4
#define buttonPin 3
#define redLedPin 12
#define blueLedPin 11
bool pressed = false;
unsigned long lastPress = 0;
void setup() {
// put your setup code here, to run once:
pinMode(potPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(redLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), handleInterrupt, CHANGE);
Serial.begin(9600);
}
void handleInterrupt() {
bool buttonState = digitalRead(buttonPin);
if (!buttonState) {
lastPress = millis();
}
pressed = !buttonState; // Inverterer siden jeg bruker knappen i pullup konfigurasjon
}
void loop() {
// put your main code here, to run repeatedly:
static bool redState = LOW;
static bool blueState = LOW;
if (pressed) {
redState = HIGH;
if (lastPress + 1000 < millis()) {
blueState = HIGH;
}
}
else {
redState = LOW;
blueState = LOW;
}
digitalWrite(redLedPin, redState);
digitalWrite(blueLedPin, blueState);
}