Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Assignment 2. Digital I/O

Project Members: 
Seung Wook Kim

[Description]

- Finding a good diffuser: Film case & Parchment Paper

- Control colors of LEDs by both

  a) multiple key presses, and

  b) color names (yellow, orange and purple) - optional

 

[Components]

 - LED x 3 (R, G, B) 

- Resistor X 3 (stripes: red-red-brown-gold)

- White film case

- Parchment paper

 

[Adurino Code] 


 /* Enhanced RGB LEDs */

char inputString[100];

char c;

char color;

int value[3] = {0, 0, 0};

int pin[3] = {9, 10, 11};

void setup() {

  pinMode(pin[0], OUTPUT); // Red

  pinMode(pin[1], OUTPUT); // Green 

  pinMode(pin[2], OUTPUT); // Blue

  Serial.begin(9600);

  analogWrite(pin[0], 250);

  analogWrite(pin[1], 20);

  analogWrite(pin[2], 50);

  Serial.println("enter color info:  r, g, b, yellow, orange or purple"); 

}

void loop () {

  readInputString(inputString);   

  c = inputString[0];

  int i=0, j=0;

  if ( c == 'r' || c == 'g' || c == 'b' ) { // *** [homework No. 2] ***  

    while (i < 100 && inputString[i] != '\0') {

        color = inputString[i];

        switch (color) {

          case 'r': j=0; break;

          case 'g': j=1; break;

          case 'b': j=2; break;

        }

        value[j] = (value[j] + 10) % 255;

        analogWrite(pin[j], value[j]);

        Serial.print("setting color ");

        Serial.print(color);

        Serial.print(" to ");

        Serial.println(value[j]);      

        i++;

    }

  }

  else if (c>='a' && c<='z') { // *** [homework No. 3] ***

    if (!strcmp(inputString, "yellow")) {

      analogWrite(pin[0], 255);

      analogWrite(pin[1], 255);

      analogWrite(pin[2], 0);

    }

    else if(!strcmp(inputString, "orange")) {

      analogWrite(pin[0], 180);

      analogWrite(pin[1], 127);

      analogWrite(pin[2], 0);

    }

    else if(!strcmp(inputString, "purple")) {

      analogWrite(pin[0], 255);

      analogWrite(pin[1], 0);

      analogWrite(pin[2], 255);

    }

      Serial.print("Setting color to ");

      Serial.print(inputString);

      Serial.println();   

  }

  int k;

  for (k=0;k<10;k++) {

    inputString[k] = 0; // initialize all strings

  }

  delay(100);

void readInputString (char *strArray) {

  int i = 0;

  if(!Serial.available()) {

    return;

  }

  while (Serial.available()) {

    strArray[i] = Serial.read();

    i++;

  }

}


 

[Images]

assign 2


Comments

GSI Comments

Nice work doing all three parts of the assignment. I like the combination of parchment paper and the film canister for the diffuser -- it does a good job of spreading out the light and creating a three-dimensional object with it. Keep up the good work.


Powered by Drupal - Design by Artinet