Description:
This lab was about digitial input and output, and managing the output by varying the type and method of the input. For this, I set up the breadboard to run the fading lights configuration of the 3 LEDs hooked up to 220ohms resistors in series which are then hooked up to each other in parallel to the arduino. Then we modified the code in serial_led_rgb file to output the increased light strength in the leds based on every 'r' or 'b' or 'g', by 10%. This was done by changing the colorVal variable to an integer that wouldn't not vary, and reseting the leds when they hit the 255 mark.
Components Used:
1xArduino
1x Breadboard
3x LED lights (red, blue and green)
7x wires
3x 220 ohm resistors
1x computer
1x bag of salt
Diffuser:
I basically wanted to experiment with different kitchen items like a bag of salt. I thought it would be interesting to use as a diffuser because it is a subtle diffuser and the diffusion can be controlled by shape of the bag and how the salt particles are spread out within the bag (and also how they are adhered to the bag, if they are adhered to it at all).
Code: (For the modified serial_led_rgb file)
/*
* Serial RGB LED
* ---------------
* Serial commands control the brightness of R,G,B LEDs
*
* Command structure is "<colorCode><colorVal>", where "colorCode" is
* one of "r","g",or "b" and "colorVal" is a number 0 to 255.
* E.g. "r0" turns the red LED off.
* "g127" turns the green LED to half brightness
* "b64" turns the blue LED to 1/4 brightness
*
* Created 18 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won't work properly
char colorCode;
int colorVal = 255/10;
int redPin = 9; // Red LED, connected to digital pin 9
int greenPin = 10; // Green LED, connected to digital pin 10
int bluePin = 11; // Blue LED, connected to digital pin 11
int redColorVal = 0;
int blueColorVal = 0;
int greenColorVal = 0;
void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 0); // set them all to mid brightness
analogWrite(greenPin, 0); // set them all to mid brightness
analogWrite(bluePin, 0); // set them all to mid brightness
Serial.println("enter color command (e.g. 'r' or 'g' or 'b') :");
}
void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);
colorCode = serInString[0];
if( colorCode == 'r' || colorCode == 'g' || colorCode == 'b' ) {
Serial.print("setting color ");
Serial.print(colorCode);
Serial.print(" to ");
serInString[0] = 0; // indicates we've used this string
if(colorCode == 'r') {
redColorVal += colorVal;
redColorVal = redColorVal % 255;
Serial.print(redColorVal);
analogWrite(redPin, redColorVal); }
else if(colorCode == 'g') {
greenColorVal += colorVal;
greenColorVal = greenColorVal % 255;
Serial.print(greenColorVal);
analogWrite(greenPin, greenColorVal); }
else if(colorCode == 'b') {
blueColorVal += colorVal;
blueColorVal = blueColorVal % 255;
Serial.print(blueColorVal);
analogWrite(bluePin, blueColorVal); }
Serial.println();
}
delay(100); // wait a bit, for serial data
}
//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}
- Login to post comments