More
See all Show me
Getting Started with Arduino

makezine.com/getstartedarduino

Let's look at the interesting parts of the code: state is a variable that stores either 0 or 1 to remember whether the LED is on or off. After the button is released, we initialise it to 0 (LED off).

Later, we read the current state of the button, and if it's pressed (val == HIGH), we change state from 0 to 1, or vice versa. We do this using a small trick, as state can be only either 1 or 0. The trick I use involves a small mathematical expression based on the idea that 1 – 0 is 1 and 1 – 1 is 0:
state = 1 - state;
This conversation is missing your voice. Take five seconds to join Vimeo or log in.

Advertisement

Statistics

  •  
    plays
    likes
    comments
  • Total
    plays 90
    likes 0
    comments 0
  • Dec 1st
    plays 0
    likes 0
    comments 0
  • Nov 30th
    plays 0
    likes 0
    comments 0
  • Nov 29th
    plays 0
    likes 0
    comments 0
  • Nov 28th
    plays 1
    likes 0
    comments 0
  • Nov 27th
    plays 1
    likes 0
    comments 0
  • Nov 26th
    plays 0
    likes 0
    comments 0
  • Nov 25th
    plays 0
    likes 0
    comments 0
  • Nov 24th
    plays 1
    likes 0
    comments 0
Previous Week

Downloads

Please join Vimeo or log in to download the original file. It only takes a few seconds.