//Echoboard: Attiny44, button and LED //In this code the duration of the Blink is set by the time the button is pressed. int ledPin = PA7; //Set the LED pin int ledState = LOW; //Set LED initial state long ledStart = 0; //Last time the LED was updated long ledBlink = 1000; //LED blink interval int buttonPin = PA3; //Set the button pin int buttonState = HIGH; //Set the button initial state long buttonPressTime = 0; //Time with the button pressed void setup() { pinMode(buttonPin, INPUT); //Set the button pin as an input pinMode(ledPin, OUTPUT); //Set the LED pin as an output } void loop() { buttonState = digitalRead(buttonPin); //Read the state of the button pin if (buttonState==LOW && buttonPressTime==0) { //Check if the button is pressed buttonPressTime = millis(); //Check the time with the button pressed } if (buttonState==HIGH && buttonPressTime!=0) { //Check if the button is no longer pressed ledBlink = millis() - buttonPressTime; //Sets the new interval for the blink from the subtraction of the execution time of the program minus the time with the button pressed buttonPressTime = 0; //Reset the timer, ready for a new time reading } if (millis() - ledStart > ledBlink) { //Check if the time the button was pressed is less than the blink interval ledStart = millis(); //Update ledStart if (ledState == LOW) //Check if the previous ledState was LOW ledState = HIGH; //Set the new ledState on HIGH to blink ON else ledState = LOW; //Set the new ledState on LOW to blink OFF digitalWrite(ledPin, ledState); //Set the new ledState on the ledPin, blinking the LED } }