Making Things Interactive

January 29, 2008

Ladyada Tutorials

Filed under: 3: LadyAda Tutorials,Assignments,Lingshui Wang — lingshui @ 1:32 am

Here’s a script for a blinking light pattern, 3 lights blink in succession (3 times), then all blink in unison (3 times).

int RedPin = 13;
int GreenPin = 12;
int BluePin = 11;
void setup()
{
	pinMode(RedPin, OUTPUT);
	pinMode(GreenPin, OUTPUT);
	pinMode(BluePin, OUTPUT);

}void loop()
{
	digitalWrite(RedPin, HIGH);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, HIGH);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, HIGH);
	delay(250);
	digitalWrite(RedPin, HIGH);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, HIGH);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, HIGH);
	delay(250);
	digitalWrite(RedPin, HIGH);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, HIGH);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, HIGH);
	delay(250);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(250);
	digitalWrite(RedPin, HIGH);
	digitalWrite(GreenPin, HIGH);
	digitalWrite(BluePin, HIGH);
	delay(1000);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(500);
	digitalWrite(RedPin, HIGH);
	digitalWrite(GreenPin, HIGH);
	digitalWrite(BluePin, HIGH);
	delay(1000);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(500);
	digitalWrite(RedPin, HIGH);
	digitalWrite(GreenPin, HIGH);
	digitalWrite(BluePin, HIGH);
	delay(1000);
	digitalWrite(RedPin, LOW);
	digitalWrite(GreenPin, LOW);
	digitalWrite(BluePin, LOW);
	delay(500);
}

Here’s a script that includes a switch (light blinks 4 times when switch is activated):

int ledPin = 12;
int switchPin = 2;
int val;
void setup() {
	pinMode(ledPin, OUTPUT);
	pinMode(switchPin, INPUT);

}void loop(){
	val = digitalRead(switchPin);
	if (val == HIGH) {
		digitalWrite(ledPin, LOW);
	}
	if (val == LOW) {
		digitalWrite(ledPin, HIGH );
		delay(250);
		digitalWrite(ledPin, LOW);
		delay(250);
		digitalWrite(ledPin, HIGH);
		delay(250);
		digitalWrite(ledPin, LOW);
		delay(250);
		digitalWrite(ledPin, HIGH );
		delay(250);
		digitalWrite(ledPin, LOW);
		delay(250);
		digitalWrite(ledPin, HIGH);
		delay(250);
		digitalWrite(ledPin, LOW);
		delay(250);
	}
}
Advertisements

Leave a Comment »

No comments yet.

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

Blog at WordPress.com.

%d bloggers like this: