EGGuino with Pots

Submitted by deb on Sun, 02/17/2013 - 20:37

Description

In this assignment I set my existing "EGGuino" diffuser project to be controlled with 3 potentiometers (pots). Each separate pot uses Arduino's analog pins to control the brightness of 3 separate LEDs. If the user wants to produce a specific color, they can adjust the pots as they reference the serial, which continuously streams the value of each pot. The serial will print the name of classic colors (e.g. "Purple" or "Turquois") when the correct light combination is entered.  The user can also force a specific LED to flash by entering "Red", "Blue", or "Green" into the serial. The selected light, alone, will then flash 3 times at a speed controlled by PotC and then return the lights to the original pot values.

 

 

Components Used

  • 3 LED Lights
  • Breadboard
  • 3 lead wires coming from Arduino board
  • 3 220 Ω resisters
  • USB Cable
  • Packing Peanut
  • Egg shell
  • Arduino UNO
  • 4 grounding wires (3 short 1 long)
  • rubber band
  • 3 Potentiometers (Pots)
    • Grounding wire from pots
    • Analog wire from pots
    • Lead wires from pots
    • 1 Lead wire from Arduino
    • 1 Grounding wire from Arduino
    • 3 Analog wires from Arduino

 

Code


// Analog pin settings
int aIn = 0;    // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 1;    //   (Connect power to 5V and ground to analog ground)
int cIn = 2;  

// Digital pin settings
int aOut = 9;   // LEDs connected to digital pins 9, 10 and 11
int bOut = 10;  //   
int cOut = 11;  

// Values
int aVal = 0;   // Variables to store the input from the potentiometers
int bVal = 0;  
int cVal = 0;  

// Variables for comparing values between loops
int i = 0;            // Loop counter
int wait = (1000);    // Delay between most recent pot adjustment and output

int checkSum     = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens         = 3; // Sensitivity threshold, to prevent small changes in
                      // pot values from triggering false reporting
 

// FLAGS
int PRINT = 1; // Set to 1 to output values


// FORCING COLORS
String colorCode;
char serInString[100];  // Array that will hold the different bytes of the string 100=100char
int q = 0;                      // Must state how long the array will be else it won't work properly
                       
                        
void setup()
{
  pinMode(aOut, OUTPUT);   // Sets the digital pins as output
  pinMode(bOut, OUTPUT);   
  pinMode(cOut, OUTPUT);
  Serial.begin(9600);     // Open serial communication for reporting
}




void loop()
{
 
  i += 1; // Count loop

  aVal = analogRead(aIn) / 4;  // Read input pins, convert to 0-255 scale
  bVal = analogRead(bIn) / 4;
  cVal = analogRead(cIn) / 4;  

  analogWrite(aOut, aVal);    // Send new values to LEDs
  analogWrite(bOut, bVal);
  analogWrite(cOut, cVal);

 if (i % wait == 0)                // If enough time has passed
 {    
    checkSum = aVal+bVal+cVal;      // Add up the 3 values
    if ( abs(checkSum - prevCheckSum) > sens )   // If old and new values differ...

                                                                       // above sensitivity threshold
    {
      if (PRINT)                 // Continuous print of pot values to help users...

                                       //  zero in on the colors they want
      {
        Serial.print("A: ");       
        Serial.print(aVal);         
        Serial.print("\t");
        Serial.print("B: ");        
        Serial.print(bVal);
        Serial.print("\t");
        Serial.print("C: ");                
        Serial.println(cVal);
        PRINT = 1;
      }
    }
    

////////   FORCING COLORS TO FLASH

memset(serInString, 0, 100);     // Clear the string
readSerialString(serInString);   // Read the serial port and create a string out of what you read
colorCode = serInString;

    if( colorCode == "Red" ) {
    while (q < 3){
      {
  analogWrite(aOut, 255);    // Send values to LEDs
  analogWrite(bOut, 0);
  analogWrite(cOut, 0);
  delay(10*cVal);
  analogWrite(aOut, 0);     // Send off values to LEDs
  analogWrite(bOut, 0);
  analogWrite(cOut, 0);
  delay(10*cVal);           // Flash speed controled by cVal - blue light pot
  q++;
    }
  }
    }
 
    if( colorCode == "Green" ) {
    while (q < 3){
      {
  analogWrite(aOut, 0);    // Send values to LEDs
  analogWrite(bOut, 255);
  analogWrite(cOut, 0);
  delay(10*cVal);
  analogWrite(aOut, 0);    // Send off values to LEDs
  analogWrite(bOut, 0);
  analogWrite(cOut, 0);
  delay(10*cVal);          // Flash speed controled by cVal - blue light pot
  q++;
    }
  }
    }
    if( colorCode == "Blue" ) {
    while (q < 3){
      {
  analogWrite(aOut, 0);    // Send values to LEDs
  analogWrite(bOut, 0);
  analogWrite(cOut, 255);
  delay(10*aVal);
  analogWrite(aOut, 0);    // Send off values to LEDs
  analogWrite(bOut, 0);
  analogWrite(cOut, 0);
  delay(10*aVal);          // In this case, flash speed is controlled by aVal - red light pot
  q++;
    }
  }
    }
    q=0;   // **** Reset q so you can force colors more than once
          //  **** Return to existing values before the forced flash
 
 
 
//////// DETECTING COLORS
//////// Getting 'Blue' is easy but can you get the illusive 'Purple'?

    
    if (aVal == 255 && bVal == 0 && cVal == 0)    //Serial identifies colors
    {
       Serial.print ("Red Rum RED RUM!");
       Serial.print ("\n");
    }
    
     if (aVal == 131 && bVal == 0 && cVal == 30)
    {
       Serial.print ("Pink");
       Serial.print ("\n");
    }
    
     if (aVal == 255 && bVal == 0 && cVal == 210)
    {
       Serial.print ("Pur-ple rain. Purple RAIN!");
       Serial.print ("\n");
    }
    
     if (aVal == 0 && bVal == 0 && cVal == 255)
    {
       Serial.print ("Blue");
       Serial.print ("\n");
    }
    
     if (aVal == 0 && bVal == 231 && cVal == 216)
    {
       Serial.print ("Turquoise");
       Serial.print ("\n");
    }
    
     if (aVal == 0 && bVal == 255 && cVal == 0)
    {
       Serial.print ("Green");
       Serial.print ("\n");
    }
    
     if (aVal == 255 && bVal == 70 && cVal == 0)
    {
       Serial.print ("Orange");
       Serial.print ("\n");
    }
    
  }
 
 
 
}
 
//////// READ SERIAL

void readSerialString (char *strArray) {
  int j = 0;
  if(!Serial.available()) {
    return;
  }
  while (Serial.available()) {
    strArray[j] = Serial.read();
    j++;
  }
}

EGGuino with Pots 1
EGGuino with Pots 2
EGGuino with Pots 3
0
Your rating: None
Drupal theme by Kiwi Themes.