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=http://www.youtube.com/watch?v=VKqE7xAhVAA ]

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){
      analogWrite(8,255);
      if (flag > 3){
        analogWrite(9, 15);
        if (flag > 4){
          analogWrite(9,255);
          if (flag > 5){
            analogWrite(10,15);
            if (flag > 6){
              analogWrite(10,255);
              if (flag > 7) {
                analogWrite(11,15);
                if (flag > 8 ) {
                  analogWrite(11,255);
                }
              }
            }
          }
        }
      }
    }
  }
  Serial.println(count);       // used to check the accuracy of the counter
  delay(100);
  digitalWrite(ledPin,LOW);
  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

Advertisements

2 Comments »

  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.
    -Lea

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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

Create a free website or blog at WordPress.com.

%d bloggers like this: