Making Things Interactive

February 5, 2008

Assignment 4, Counting Sensor

Filed under: 4: Counting Sensor Input,Siddartha Butalia — sbutalia @ 4:20 am

with this assignment i wanted to explore output options more as im going to be diving into different sensor inputs for my projects. lights tend to be interesting so I wanted to experiment with differnt ways of outputting actions with lights. My output is a series of growing and fading LEDs which are dependant on how long you hold down the switch for. I still have a counter which adds up the total number of button presses and keeps track of it.

[ youtube= ]

Link to Video

Here is the code:

int switchPin = 2;              // Switch connected to digital pin 2
int count = 0;                  // Counter
int ledPin = 13;                // test pin
int flag = 0;                   // variable to check for holding of the button
void setup()                    // run once, when the sketch starts
  Serial.begin(9600);           // set up Serial library at 9600 bps
  pinMode(switchPin, INPUT);    // sets the digital pin as input to read switch
  for (int i=8; i  1){                      // the fancy LED output
    analogWrite(8, 15);
    if (flag > 2){
      if (flag > 3){
        analogWrite(9, 15);
        if (flag > 4){
          if (flag > 5){
            if (flag > 6){
              if (flag > 7) {
                if (flag > 8 ) {
  Serial.println(count);       // used to check the accuracy of the counter
  if(flag < 2){     digitalWrite(11,LOW);     delay(50);     digitalWrite(10,LOW);     delay(50);     digitalWrite(9,LOW);     delay(50);     digitalWrite(8,LOW);   } }[/sourcecode] and i have no idea why my youtube thing wont work or why this wordpress link keeps coming inside my sourcecode



  1. The wordpress link keeps coming into your sourcecode because, for some inane reason, WordPress thinks we want automatic smilies replacing things like colon-end-parenthesis and eight-end-parenthesis, even in formatted code. I had the same problem. Just put a space between the eight and the end parenthesis in the code.

    Comment by tovelet — February 5, 2008 @ 9:14 am | Reply

  2. Fixed the stupid smiley problem.

    Comment by jet — February 5, 2008 @ 1:11 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: