0

RGB Help Lesson 3
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RGB Help Lesson 3

by mjpcarbon on Mon Mar 10, 2014 7:54 pm

I am having a bit of trouble from what would seem to be simple
I should be past this and able to figure it out on my own but cannot so here I go with another First Grade problem
When I do the Lesson 3 tutorial not all the colors correspond, I have triple checked the 3 wires and still cannot get the proper color to names.
The only one is RED, I must be missing the obvious and apologize for the time someone will have to spend to help me
Red to Pin 11
Green to Pin 10
Blue to Pin 11
5v to Anode (example is grounded but not my issue)
First color in the sketch is supposed to be red and it is Aqua and the last of the 6 colors is Red ( I changed the delay to be sure of which is which)
What am I doing wrong
Also another proof is if I null all the colors except RED the LED is Aqua proving something is array

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by adafruit_support_rick on Mon Mar 10, 2014 8:57 pm

Sounds like you have a common cathode LED after all. Try grounding the cathode pin instead of connecting it to 5V

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Help Lesson 3

by mjpcarbon on Mon Mar 10, 2014 9:55 pm

I did then nothing works

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by adafruit_support_rick on Mon Mar 10, 2014 10:01 pm

Post a picture showing your wiring.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Help Lesson 3

by mjpcarbon on Tue Mar 11, 2014 8:11 am

rgb.JPG
wiring
rgb.JPG (126.61 KiB) Viewed 1674 times
keep in mind the sketch works but colors are incorrect

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by adafruit_support_rick on Tue Mar 11, 2014 11:38 am

OK, so you're using a Common Anode LED. That means that everything is backwards from the sample code, which assumes Common Cathode. The tutorial needs to be updated somehow, because switching from CC to CA requires more than just switching one pin from GND to 5V. The color logic also needs to be inverted.

Try this code:
Code: Select all | TOGGLE FULL SIZE
/*
Adafruit Arduino - Lesson 3. RGB LED
*/

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

//uncomment this line if using a Common Anode LED
#define COMMON_ANODE

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT); 
}

void loop()
{
  setColor(255, 0, 0);  // red
  delay(1000);
  setColor(0, 255, 0);  // green
  delay(1000);
  setColor(0, 0, 255);  // blue
  delay(1000);
  setColor(255, 255, 0);  // yellow
  delay(1000); 
  setColor(80, 0, 80);  // purple
  delay(1000);
  setColor(0, 255, 255);  // aqua
  delay(1000);
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue); 
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Help Lesson 3

by mjpcarbon on Tue Mar 11, 2014 11:50 am

oooooh
I will do it this evening and report thank you

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by mjpcarbon on Tue Mar 11, 2014 8:04 pm

Still really doesnt work properly
I nulled all but red green blue yet it blinks red blue green ?
Also confusing is the fact it only works with 5v ?
Wow something so simple is really confusing

However if you rename Green to pin9 and Blue to 10 it works right.

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by adafruit_support_rick on Wed Mar 12, 2014 10:29 am

Yeah, RGB LEDs can be confusing. But at least you got it going, right?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Help Lesson 3

by mjpcarbon on Wed Mar 12, 2014 10:43 am

Yes, it works great so now I have a related question.
If I were to use it in a temp situation for example
If the sensor reached 100 degrees it would lite RED
Would the code read " ifpin?=_(setcolorRED)or something along those lines ?

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by adafruit_support_rick on Wed Mar 12, 2014 10:56 am

You would do something along these lines:
Code: Select all | TOGGLE FULL SIZE
 temperature = <call whatever reads the temperature here>;
  if (100 <= temperature)
  {
    setColor(255, 0, 0);  //red
  }
  else
  {
    setColor(0, 0, 255);  /blue
  }

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Help Lesson 3

by mjpcarbon on Wed Mar 12, 2014 11:11 am

thank you

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by mjpcarbon on Wed Mar 12, 2014 8:46 pm

I am now trying to mix the rgb sketch with the tmp06 sketch and I am getting a compile error that states
setColor was not declared in this scope.
So as I look at the Lesson 3 sketch I dont see where 'setColor' was ever declared ?

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

by adafruit_support_rick on Thu Mar 13, 2014 9:49 am

setColor is declared below loop() in the lesson 3 sketch:
Code: Select all | TOGGLE FULL SIZE
void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue); 
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Help Lesson 3

by mjpcarbon on Thu Mar 13, 2014 8:36 pm

I give up on this one more error messages than I can even share,
So I decided to do it the hard way with the RGB and it works like I want it to, then I wanted to blink one of the colors.
I thought I could add delay(1000); below the LOW line and guess what, it doesnt blink :x
I have tried putting the delay in a couple places but am once again missing it.
Code: Select all | TOGGLE FULL SIZE
//TMP36 Pin Variables
int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade
int ledPin = 9;        // LED connected to digital pin 13 Green LED
int ledPin2 = 11;       // LED connected to digital pin 12 Red LED
/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  Serial.begin(9600);  //Start the serial connection with the copmuter
                       //to view the result open the serial monitor
                       //last button beneath the file bar (looks like a box with an antenae)
}
 
void loop()                     // run over and over again
{
 float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the temperature sensor
 temperature = (((temperature - .5) * 100)*1.8) + 32;          //converting from 10 mv per degree wit 500 mV offset
                                                  //to degrees ((volatge - 500mV) times 100)
 Serial.println(temperature);                     //printing the result
 Serial.println(" Fahrenheit");
 delay(1000);                                     //waiting a second
if (temperature > 75) digitalWrite(11,HIGH);
if (temperature < 75) digitalWrite(11,LOW);
if (temperature > 75) digitalWrite(9,LOW);
if (temperature < 75) digitalWrite(9,HIGH);

}

/*
 * getVoltage() - returns the voltage on the analog input defined by
 * pin
 */
float getVoltage(int pin){
 return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
                                        // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Please be positive and constructive with your questions and comments.