Making Furniture Interactive

September 25, 2007

Example of how to post code

Filed under: Course Materials,Examples — jet @ 8:54 am

To post source code, you need to put a wrapper around it using “sourcecode”. Use the “Code” tab of the editor to insert the “sourcecode” tags, not the “Visual” tab. The “Visual” tab does all sorts of magic that will cause the “sourcecode” tag to not be recognized.

[sourcecode language="cpp"]

[put your source here]

[/sourcecode]

/*
* AnalogInput
* by DojoDave <http://www.0j0.org>
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin 2.
*
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

// int cellPin = 0;    // select the input pin for the potentiometer
int ledPin = 12;   // select the pin for the LED
int cdsPin = 0;
int cdsVal =0;
int ledDelay =0;

void setup() {
pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(cdsPin, INPUT);
Serial.begin(9600);
}

void loop() {

cdsVal = analogRead(cdsPin);
Serial.println(cdsVal);
ledDelay = cdsVal;

digitalWrite(ledPin, HIGH);  // turn the ledPin on
delay(ledDelay);
digitalWrite(ledPin, LOW);   // turn the ledPin off
delay(ledDelay);

}

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

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: