Making Things Interactive

February 28, 2008

3: LadyAda Tutorials

Filed under: 3: LadyAda Tutorials — jmarshman @ 11:27 pm

Documentation of tutorials (unable to post until now):

Simple circuit, three LED’s

Simple switch

Alternating switch

Alternating switch w/ changing 3 LED’s


/*
 Alternating switch
 */

int switchPin = 2;              // switch is connected to pin 2
int ledPin = 13;                // led is connected to pin 13
int val;                        // variable for reading the pin status
int buttonState;                // variable to hold the last button state

void setup() {
  pinMode(switchPin, INPUT);    // Set the switch pin as input
  pinMode(ledPin, OUTPUT);      // set the led pin as an output
  Serial.begin(9600);           // Set up serial communication at 9600bps
  buttonState = digitalRead(switchPin);   // read the initial state
}

void loop(){
  val = digitalRead(switchPin);      // read input value and store it in val

  if (val != buttonState) {          // the button state has changed
    if (val == LOW) {                // check if the button is pressed
      Serial.println("Button just pressed");
      digitalWrite(ledPin, LOW);
    } else {                         // the button is not pressed
      Serial.println("Button just released");
      digitalWrite(ledPin, HIGH);
    }
  }

  buttonState = val;                 // save the new state in our variable
}

February 5, 2008

My code

Filed under: 3: LadyAda Tutorials — Dae @ 2:10 pm

tutorial3


/*
 * from ladyada tutoria 3
 */

int greenPin = 12;
int bluePin = 11;
int redPin = 10;

void setup()           
{
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(redPin, OUTPUT);
 
}

void loop()                    
{
  digitalWrite(bluePin, HIGH);
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, LOW);
  delay(500);             
  digitalWrite(bluePin, LOW);
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, LOW);
  delay(500);
  digitalWrite(bluePin, LOW);
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, HIGH);
  delay(500);               
  digitalWrite(redPin, HIGH);
  digitalWrite(bluePin, HIGH);
  digitalWrite(greenPin, LOW);
  delay(500);
  digitalWrite(bluePin, HIGH);
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, HIGH);
  delay(500);               
  digitalWrite(bluePin, LOW);
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, HIGH);
  delay(500);             
  digitalWrite(bluePin, HIGH);
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, HIGH);
  delay(500);             
  digitalWrite(bluePin, LOW);
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, LOW);
  delay(500);             
}

February 1, 2008

My Codes

Filed under: 3: LadyAda Tutorials,Assignments,Gee Kim — gskim @ 5:11 pm

My Blink

img_0446.jpg

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
digitalWrite(ledPin, HIGH);   // sets the LED on
delay(500);                  // waits for a second
digitalWrite(ledPin, LOW);    // sets the LED off
delay(900);                  // waits for a second
}

Alternating Green and Red

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11

void setup()                      // run once, when the sketch starts
{
pinMode(redPin, OUTPUT);        // sets the digital pin as output
pinMode(greenPin, OUTPUT);      // sets the digital pin as output
}

void loop()                       // run over and over again
{
digitalWrite(redPin, HIGH);     // sets the Red LED on
digitalWrite(greenPin, LOW);   // sets the Green LED on
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);      // sets the Red LED off
digitalWrite(greenPin, HIGH);    // sets the Green LED off
delay(500);                     // waits for half a second
}

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin = 10;

void setup()                      // run once, when the sketch starts
{
pinMode(redPin, OUTPUT);        // sets the digital pin as output
pinMode(greenPin, OUTPUT);      // sets the digital pin as output
pinMode(bluePin, OUTPUT);
}

void loop()                       // run over and over again
{
digitalWrite(redPin, HIGH);     // sets the Red LED on
digitalWrite(greenPin, HIGH);   // sets the Green LED on
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);      // sets the Red LED off
digitalWrite(greenPin, LOW);    // sets the Green LED off
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
}

Color Mixing

img_0451.jpg

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin = 10;

void setup()                      // run once, when the sketch starts
{
pinMode(redPin, OUTPUT);        // sets the digital pin as output
pinMode(greenPin, OUTPUT);      // sets the digital pin as output
pinMode(bluePin, OUTPUT);
}

void loop()                       // run over and over again
{
digitalWrite(redPin, HIGH);     // sets the Red LED on
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);     // sets the Red LED on
delay(500);                     // waits for half a second
digitalWrite(redPin, HIGH);     // sets the Red LED on
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(redPin, LOW);     // sets the Red LED on
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
digitalWrite(greenPin, HIGH);    // sets the Green LED off
digitalWrite(bluePin, HIGH);
delay(500);                     // waits for half a second
digitalWrite(greenPin, LOW);    // sets the Green LED off
digitalWrite(bluePin, LOW);
delay(500);                     // waits for half a second
digitalWrite(greenPin, HIGH);    // sets the Green LED off
delay(500);                     // waits for half a second
digitalWrite(greenPin, LOW);    // sets the Green LED off
delay(500);                     // waits for half a second
digitalWrite(greenPin, HIGH);    // sets the Green LED off
digitalWrite(redPin, HIGH);     // sets the Red LED on
delay(500);                     // waits for half a second
digitalWrite(greenPin, LOW);    // sets the Green LED off
digitalWrite(redPin, LOW);     // sets the Red LED on
delay(500);                     // waits for half a second
}

HelloWorld

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps
Serial.println(“Hello world!”);  // prints hello with ending line break
}

void loop()                       // run over and over again
{
// do nothing!
}

HelloWorld 20 Times with Delay

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps

}

void loop()                       // run over and over again
{
Serial.println(“Hello world!”);  // prints hello with ending line break
delay(1000);
}

DriveCalc


/*
* Drive size calculator!
*/

int drive_gb = 100;
long drive_mb;
long drive_kb;
long real_drive_mb;
long real_drive_kb;

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps

Serial.print(“Your HD is “);
Serial.print(drive_gb);
Serial.println(” GB large.”);

drive_mb = drive_gb;
drive_mb = drive_mb * 1024;
drive_kb = drive_mb * 1024;

Serial.print(“In theory, it can store “);
Serial.print(drive_mb);
Serial.print(” Megabytes, “);
Serial.print(drive_kb);
Serial.println(” Kilobytes.”);

real_drive_mb = drive_gb;
real_drive_mb = real_drive_mb * 1000;
real_drive_kb = real_drive_mb * 1000;

Serial.print(“But it really only stores “);
Serial.print(real_drive_mb);
Serial.print(” Megabytes, “);
Serial.print(real_drive_kb);
Serial.println(” Kilobytes.”);

Serial.print(“You are missing “);
Serial.print(drive_kb – real_drive_kb);
Serial.println(” Kilobytes!”);
}

void loop()                       // run over and over again
{
}

Turning on LED with Switch

img_0455.jpg

January 30, 2008

Tutorials: RGB Mood Light

Filed under: 3: LadyAda Tutorials,Jesse Chorng — Jesse @ 3:13 am

The pulsing LEDs started giving me a headache while I was learning the tutorials. I then started thinking about how I could write something smoother and thus be gentler on my nogin. After looking around and finding something on MAKE (always do), I was able to see how they created gradual increases/decreases in light.  Moreover, I spent much more time than I had expected to finding stuff and fixing code, which I guess was the point of the tutorials and getting to know the Arduino.  Here’s a video of it in action:

 

int count = 0;                    // Sets up a counter for loops
int intredPin = 11;                   // Red LED connected to digital pin 11
int greenPin = 10;                    // Green LED connected to digital pin 10
int bluePin = 9;                      // Blue LED connected to digital pin 9

void setup()
{
   pinMode(redPin, OUTPUT);
   pinMode(greenPin, OUTPUT);
   pinMode(bluePin, OUTPUT);
}

void loop()
{    
   for (count = 0 ; count <= 255 ; count -= 5)    // Count up by 5 to gradually increase steps
   {
   analogWrite(redPin, count);                    // Gradually increases
   digitalWrite(greenPin, HIGH);                  // On
   digitalWrite(bluePin, LOW);                    // Off
   delay(50);
   }    

   for (count = 255 ; count >= 0 ; count -= 5)    // Continues pattern over and over
   {
   digitalWrite(redPin, HIGH );                   // Remains on
   analogWrite(greenPin, count);                  // Gradually decreases
   digitalWrite(bluePin, LOW);                    // Remains off
   delay(50);
   }
 
   for (count = 0 ; count <= 255 ; count -= 5)    
   {
   digitalWrite(redPin, HIGH);                    
   digitalWrite(greenPin, LOW);
   analogWrite(bluePin, count);
   delay(50);
   }    

   for (count = 255 ; count >= 0 ; count -= 5)
   {
   analogWrite(redPin, count);
   digitalWrite(greenPin, LOW);
   digitalWrite(bluePin, HIGH);
   delay(50);
   }
   
   for (count = 0 ; count <= 255 ; count -= 5)
   {
   digitalWrite(redPin, LOW);
   analogWrite(greenPin, count);
   digitalWrite(bluePin, HIGH);
   delay(50);
   }    

   for (count = 255 ; count >= 0 ; count -= 5)
   {
   digitalWrite(redPin, LOW);
   digitalWrite(greenPin, HIGH);
   analogWrite(bluePin, count);
   delay(50);
   }
}

tutorials complete!

Filed under: 3: LadyAda Tutorials,Gaku Sato — ponkotsu @ 1:19 am

// here’s my tutorial 04 drivecalc code 

int drive_gb = 100;
long drive_kb_1024;
long drive_kb_1000;

void setup()
{
  Serial.begin(9600);

  Serial.print(“Your drive capacity is “);
  Serial.print(drive_gb);
  Serial.println(“GB.”);

  drive_kb_1024 = drive_gb;
  drive_kb_1024 = drive_kb_1024 * 1024 * 1024;
  Serial.print(“This translates to “);
  Serial.print(drive_kb_1024);
  Serial.println(“KB.”);
 
  drive_kb_1000 = drive_gb;
  drive_kb_1000 = drive_kb_1000 * 1000 * 1000;
  Serial.print(“Unfortunately, a “);
  Serial.print(drive_gb);
  Serial.print(“GB drive can only store “);
  Serial.print(drive_kb_1000);
  Serial.println(“KB,”);
  Serial.print(” which is actually “);
  Serial.print(drive_kb_1000 / 1024 / 1024);
  Serial.println(“GB.”);
 
  Serial.print(“This means you are missing “);
  Serial.print(drive_kb_1024 – drive_kb_1000);
  Serial.print(“KB or “);
  Serial.print(drive_kb_1024 / 1024 – drive_kb_1000 / 1024);
  Serial.println(“MB.”);
}

void loop()
{
}

January 29, 2008

Hello Ada

Filed under: 3: LadyAda Tutorials,Lea — tovelet @ 2:55 pm

Here is a photo of my little barebones board with the light on, mid-blink.

I don’t have three different colored LEDs of similar intensity, so I’ll point to a project from last semester of the same approximate coding difficulty, which involved timing on a simple loop: anemone sculpture. The step that I hadn’t done before with Arduino was Tutorial 4: using the serial monitor.

Assignment 3: Lady Ada Tutorials

Filed under: 3: LadyAda Tutorials,Assignments,Thomas Hendrickson — tphendrickson @ 2:34 pm

It took me a while to get the arduino program up and running… it seemed to be some problem with the current software so I used an older version (Arduino 0009).

Here’s my code for the blinking lights, it blinks three different LEDs in succession:

int redPin = 13;
int greenPin = 11;
int bluePin = 12;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop()
{
digitalWrite(redPin, HIGH);
delay(200);
digitalWrite(redPin, LOW);
digitalWrite(bluePin, HIGH);
delay(200);
digitalWrite(bluePin, LOW);
digitalWrite(greenPin, HIGH);
delay(200);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(200);
digitalWrite(bluePin, LOW);

}

Here’s my solution for the kilobyte calculator:

int drive_gb = 100;
long drive_mb;
long real_mb;
long drive_kb;
long real_kb;

void setup()
{
Serial.begin(9600);

Serial.print(“Your HD is “);
Serial.print(drive_gb);
Serial.println(” GB large.”);

drive_mb = drive_gb;
drive_mb = drive_mb * 1024;
drive_kb = drive_mb * 1024;

real_mb = drive_gb;
real_mb = real_mb * 1000;
real_kb = real_mb * 1000;

Serial.print(“It can store “);
Serial.print(drive_mb);
Serial.println(” Megabytes!”);
Serial.println();

Serial.print(“Your HD should be able to hold “);
Serial.print(drive_kb);
Serial.println(” Kilobytes.”);
Serial.println();

Serial.print(“But it actually can only hold “);
Serial.print(real_kb);
Serial.println(” Kilobytes.”)
Serial.println();

Serial.print(“This is a difference of “);
Serial.print(drive_kb – real_kb);
Serial.println(” Kilobytes”);
}

void loop()
{

}

LadyAda Tutorials

Filed under: 3: LadyAda Tutorials,Siddartha Butalia — sbutalia @ 2:08 am
Tags: , ,

Blinking

int ledPin = 13;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(1000);
}

Multiple LEDs/Colors

int Pin1 = 13;
int Pin2 = 12;
int Pin3 = 11;

void setup()
{
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
}

void loop()
{
digitalWrite(Pin1, HIGH);
delay(50);
digitalWrite(Pin2, HIGH);
delay(50);
digitalWrite(Pin3, HIGH);
delay(50);
digitalWrite(Pin1, LOW);
delay(100);
digitalWrite(Pin2, LOW);
delay(100);
digitalWrite(Pin3, LOW);
delay(100);
}

Video of LightBox

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);
	}
}

Its an amazing color changing light box!!

Filed under: 3: LadyAda Tutorials,Assignments,Christopher Bridgman — cbridgma @ 1:13 am

So here is my proof for completing the arduino tutorials. i have included a video of the color blending box project along with my code for it. I changed the timing of the code so the colors would last longer and you could see the colors longer. I also included the code for the last part of the 4th tutorial.

Code:

int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int bluePin= 10;                   // Blue LED connected to digital pin 10

void setup()                      // run once, when the sketch starts
{
  pinMode(redPin, OUTPUT);        // sets the digital pin as output
  pinMode(greenPin, OUTPUT);      // sets the digital pin as output
  pinMode(bluePin, OUTPUT);       // sets the digital pin as output
}

void loop()                       // run over and over again
{
  digitalWrite(redPin, HIGH);     // sets the Red LED on
  digitalWrite(greenPin, LOW);   // sets the Green LED off
  digitalWrite(bluePin, LOW);    // sets the Blue LED off
  delay(2000);                     // waits for half a second
  digitalWrite(redPin, HIGH);      // sets the Red LED on
  digitalWrite(greenPin, HIGH);    // sets the Green LED on
  digitalWrite(bluePin, LOW);    // sets the Blue LED off
  delay(2000);                     // waits for half a second
  digitalWrite(redPin, LOW);      // sets the Red LED off
  digitalWrite(greenPin, HIGH);    // sets the Green LED on
  digitalWrite(bluePin, LOW);    // sets the Blue LED off
  delay(2000);                     // waits for half a second
  digitalWrite(redPin, LOW);      // sets the Red LED off
  digitalWrite(greenPin, HIGH);    // sets the Green LED on
  digitalWrite(bluePin, HIGH);    // sets the Blue LED on
  delay(2000);                     // waits for half a second
  digitalWrite(redPin, LOW);      // sets the Red LED off
  digitalWrite(greenPin, HIGH);    // sets the Green LED on
  digitalWrite(bluePin, HIGH);    // sets the Blue LED on
  delay(2000);                     // waits for half a second
  digitalWrite(redPin, LOW);      // sets the Red LED off
  digitalWrite(greenPin, LOW);    // sets the Green LED off
  digitalWrite(bluePin, HIGH);    // sets the Blue LED on
  delay(2000);                     // waits for half a second
  digitalWrite(redPin, HIGH);      // sets the Red LED on
  digitalWrite(greenPin, LOW);    // sets the Green LED off
  digitalWrite(bluePin, HIGH);    // sets the Blue LED on
  delay(2000);                     // waits for half a second
}

Code for 4th tutorial:

int drive_gb = 100;
long drive_mb;
long drive_kb;
long real_drive_mb;
long real_drive_kb;
void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps

  Serial.print(“Your HD is “);
  Serial.print(drive_gb);
  Serial.println(” GB large.”);

  drive_mb = drive_gb;
  drive_mb = drive_mb * 1024;
  drive_kb = drive_mb * 1024;
 
  Serial.print(“In theory, it can store “);
  Serial.print(drive_mb);
  Serial.print(” Megabytes, “);
  Serial.print(drive_kb); 
  Serial.println(” Kilobytes.”);

  real_drive_mb = drive_gb;
  real_drive_mb = real_drive_mb * 1000;
  real_drive_kb = real_drive_mb * 1000;
 
  Serial.print(“But it really only stores “);
  Serial.print(real_drive_mb);
  Serial.print(” Megabytes, “);
  Serial.print(real_drive_kb); 
  Serial.println(” Kilobytes.”);
 
  Serial.print(“You are missing “);
  Serial.print(drive_kb – real_drive_kb); 
  Serial.println(” Kilobytes!”);
}

void loop()                       // run over and over again
{
}

Next Page »

Blog at WordPress.com.