Drinks in a Wine Glass

Description

3 LEDs diffused together with fluff in an upside down wine glass. The user can input in what type of drink they’d like. For example, they can have ‘wine’, a ‘smoothie’, or an ‘abc’ drink which is a mystery drink. The wine glass will fill with an appropriate color for each of the drinks. For the ‘abc’ mystery drink the glass fills with a fading progression through all of the colors.

Components

1 Arduino

3 LED

3 220 Ohm Resistor

1 Breadboard

4 wires

Code

/* 
 * 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
String colorCode;
int colorVal;

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

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("What would you like to drink? wine, smoothie, or abc?"); 
}

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 = String(serInString);
 if( colorCode == "wine" || colorCode == "smoothie" || colorCode == "abc" ) {
 Serial.println("We will now poor your drink!");
 if(colorCode == "wine") {
 analogWrite(redPin, 255);
 analogWrite(greenPin, 10);
 analogWrite(bluePin, 10);
 } else if(colorCode == "smoothie") {
 analogWrite(redPin, 200);
 analogWrite(greenPin, 100);
 analogWrite(bluePin, 100);
 } else if(colorCode == "abc") {
 int i = 1;
 int rValue = 0;
 int gValue = 30;
 int bValue = 60;
 int change = 5;
 while (i < 1000) {
 rValue = (rValue + change)%255;
 gValue = (gValue + change)%255;
 bValue = (bValue + change)%255;
 analogWrite(redPin, rValue);
 analogWrite(greenPin, gValue);
 analogWrite(bluePin, bValue);
 delay(50);
 if (i%50 == 0) {
 change = change*-1;
 }
 i++;
 } 
 }
 }
 
 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++;
 }
}
Screen Shot 2016-09-11 at 11.22.20 AM

Leave a Reply