/*
Forum: https://forum.arduino.cc/t/blinkzeiten-fur-knopfdruck/1309961/2
Wokwi: https://wokwi.com/projects/411375371540395009
Vorversion:
Wowki: https://wokwi.com/projects/411372918181471233
Schaltung: ec2021
Sketch: agmue
Sketch2: noiasca
Stand: 2024/10/10
*/
// ATMEL ATtiny85 1 MHz
//
// +-\/-+
// Reset 1| |8 Vcc
// Ain3 (D3) PB3 2| |7 PB2 (D2) Ain1
// Ain2 (D4) PB4 3| |6 PB1 (D1) pwm1
// GND 4| |5 PB0 (D0) pwm0
// +----+
//
const byte tasterPin = 5;
const byte led0Pin = 1;
const byte led1Pin = 2;
const byte led2Pin = 3;
const byte led3Pin = 4;
const uint32_t BLINKDAUER = 5000; // in ms
class Blink {
private:
unsigned long prevtime;
unsigned int zyklus;
unsigned int an;
public:
Blink(unsigned int _an, unsigned int _zyklus) {
zyklus = _zyklus;
an = _an;
}
boolean currentState () {
// sollte häufig aufgerufen werden, damit der jeweils aktuelle Zustand zurückgeliefert wird
if (millis() - prevtime >= zyklus) {
prevtime = millis();
}
if (millis() - prevtime < an) return true;
else return false;
}
void start () {
prevtime = millis();
}
};
Blink wechsel(600, 1000);
Blink wechsel1(900, 1300);
Blink schnell(30, 300);
Blink mittel(50, 350);
Blink timer (1, BLINKDAUER); // 1 mal für Blinkdauer
void setup()
{
pinMode ( tasterPin, INPUT_PULLUP);
pinMode ( led0Pin, OUTPUT);
pinMode ( led1Pin, OUTPUT);
pinMode ( led2Pin, OUTPUT);
pinMode ( led3Pin, OUTPUT);
}
void loop()
{
static byte schritt = 0;
switch (schritt)
{
case 0:
if (digitalRead(tasterPin) == LOW)
{
timer.start();
schritt++;
}
break;
case 1:
digitalWrite(led0Pin, wechsel.currentState() );
digitalWrite(led1Pin, wechsel1.currentState() );
digitalWrite(led2Pin, schnell.currentState() );
digitalWrite(led3Pin, mittel.currentState() );
if (timer.currentState())
{
digitalWrite(led0Pin, 0 );
digitalWrite(led1Pin, 0 );
digitalWrite(led2Pin, 0 );
digitalWrite(led3Pin, 0 );
schritt = 0;
}
break;
}
}