Lab 3 - Mood Light

Submitted by fchasen on Tue, 02/19/2013 - 22:03

 

Description

Keeping with the heart beat of my last lab, I made my diffuser display different emotions and beat faster and slower based on two potentiometers.

One controls the mood, from sad, to jealous, to mad and one control the rate of beating.

 

Components Used

  •  3 LED (Red, Green, Blue)
  • Arduino Uno
  • Breadboard
  • 3 220-ohm Resistor
  • 2 Potentiometers
  • Diffuser

 

Code

 

/* 
 * Heart Beat with Mood
 * Author: Fred Chasen
 */
 
//include support for manipulating strings.
//for a useful string comparison function, see the bottom of this file... stringsEqual()
#include <stdio.h>
#include <string.h>
 
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;
 
//Adjusted for my pin setup
int redPin   = 11;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 9;  // Blue LED,  connected to digital pin 11
 
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
 
int pulseCounter = 150;
int dir = 1;
int beat = 10;
 
int potPin = 2;
int val = 0;
 
int moodPin = 1;
int mood = 0;
 
void setup() {
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  Serial.begin(9600);
}
 
void loop () {
  //read the serial port and create a string out of what you read
  //readSerialString(serInString, 100);
  
  val = analogRead(potPin);
  mood = analogRead(moodPin);
  
  pump(val, mood);
 
 
  //Erase anything left in the serial string, preparing it for the 
  //next loop
  //resetSerialString(serInString, 100);  
 
  delay(100);  // wait a bit, for serial data
}
 
void resetSerialString (char *strArray, int length) {
  for (int i = 0; i < length; i++) {
    strArray[i] = '\0';
  }
}
 
void pump(int input, int mood) {
   
   beat = input / 16;
   
   redValue = 255 - pulseCounter;
   greenValue = 255 -  pulseCounter;
   blueValue = pulseCounter;
   
   if(mood > 684){
    blueValue = blueValue * .1;
    greenValue = greenValue * .1;
   } else if(mood > 342){
     blueValue = blueValue * .5;
     redValue = redValue * .1;
   }else{
     redValue = redValue * .1;
     greenValue = greenValue * .1;
   }
   
   analogWrite(redPin, redValue);
   analogWrite(greenPin, greenValue);
   analogWrite(bluePin, blueValue);
   
   pulseCounter = pulseCounter + beat * dir;
   
   if(pulseCounter >= 255){
     dir = dir * -1;
     pulseCounter = 255;
   }
   
   if(pulseCounter < 10){
     dir = dir * -1;
     pulseCounter = 10;
   }
   
}
 
 
 
photo-8.JPG
0
Your rating: None
Drupal theme by Kiwi Themes.