Home cutting scanning  circuits programs academy progress final project

The task here is to blink the light three times after the button is pressed. I made the assumption that a half second on and a half second off would constitute a blink

#define LED 13        //pin for LED

#define BUTTON 7    //pin for Button


int val = 0;           //set the variable to 0

int state = 0;        //set trigger to 0


void setup(){

  pinMode(LED, OUTPUT);      //set direction out

  pinMode(BUTTON, INPUT);  //set direction in

}


void loop(){

  val =digitalRead(BUTTON);    //read the button

  if (val == HIGH){                 //if pressed

  for (int i = 0; i < 3; i++) {

    digitalWrite(LED, HIGH);

    delay(500);

    digitalWrite(LED, LOW);

    delay(500);

  }

  }

}


I set out to use state as my counter but when researching how to do a “for next” loop I came across an example where they incorporated the counter “i” into the programming.

The start defines the pins or Data direction ( this was easy on the BBC computers - DDRA and DDRB had to be given values) here we just say input or output.

The loop reads the button compares that to a value (1) and if high goes into the for next loop where it light on - delay - light off delay for 3 times before it loops around the main program again.