/* What does the code do?.. Digially simulates a mala - a string of beads to count moments of mindfulness: 1 Each press of the button records a count of 1 plus 1... 2 User gets confirmation that each single count or press of button has positively registered with the processor (and is being counted) by use of the LED lighting up as a visual indciator for the user. 3 When count reaches 'target' of 5 or 10 or X then the LED blinks for so many seconds. The board: ATtiny 44 * LED attached from pin 7 (pin 6 on ATtiny) to ground * pushbutton attached to pin 3 from 5V * 10k pull up resistor, attached to pin 3 from ground The following "const" instruction assigns both the button and LED to specific pins and as constants, non-variables, and won't change */ const int buttonPin = 3; // the number of the pin connected to pushbutton const int ledPin = 7; // the number of the pin, connected to the LED // these are the variables that will change: int buttonState; // declaring button for reading the pushbutton status int count = 0; // instruct to count from 0, otherwise this is a presumption void setup() { // this will only be executed once at the beginning of the processing, //establishing inputs and outputs pinMode(ledPin, OUTPUT); // initialise the LED pin as an output: pinMode(buttonPin, INPUT); // initialise the pushbutton pin as an input: } void loop(){ // this will loop and repeat until power is lost or removed buttonState = digitalRead(buttonPin); // read the state of the pushbutton /* code will check (at 20MHz frequency) whether the pushbutton pressed. If not pressed - the button state is HIGH, and LED is off (the pull up resistor and the button/pin 3 makes the button state HIGH (off) by default. */ if (buttonState == HIGH) { // turn LED off (LED is off by default) digitalWrite(ledPin, LOW); } //otherwise..... // when button is pressed, put LED on for 1 second else { digitalWrite(ledPin, HIGH); // turn LED on: count++; delay(500); // this will avoid possibility of accidentally registering a 'count' // due to speed of buttonstate check. } if (count == 10) // once target of 10 counts has been reached, then blink LED for 5 seconds { int blinkAlert = 0; // declaring while (blinkAlert<20) /* this will loop continuosly until 'expression' inside the parenthasis () becomes false */ { digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for 0.1 second digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for 0.1 second blinkAlert ++; } count = 0; // reset counter to 0 } }