RGB Help Lesson 3

For makers who have purchased an Adafruit Starter Pack, get help with the tutorials here!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: RGB Help Lesson 3

Post by adafruit_support_rick »

This is your common anode RGB, right? So, to turn it OFF, you need to set your pin HIGH. That way, you've got 5V on both sides of the LED, and no current flows.

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

Post by mjpcarbon »

Turning it on and off works fine.
Now I want to blink one of them ?
I tried putting delay in but it did nothing although it compiled fine

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: RGB Help Lesson 3

Post by adafruit_support_rick »

I didn't see the blink delay in the code you posted?

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

Post by mjpcarbon »

I took it out due to embarrassment
Here is what I tried
if (temperature > 75) digitalWrite(11,HIGH);
if (temperature < 75) digitalWrite(11,LOW);
delay(1000);

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: RGB Help Lesson 3

Post by adafruit_support_rick »

Hmmm... I don't think I understand the effect you're trying to get. If the temperature is low, you light the LED, if the temperature is high, you turn it off. But if you blink it, you won't be able to tell the difference between high temp and low temp.

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

Post by mjpcarbon »

Im sorry.I didnt give you as much as I should have
There are two Leds and they work correctly

RED lights below 75f and goes out above 75
Green is out below 75 and lights above 75
I wish to blink RED

BTW the support on this site is amazing as well as all the products you sell.
Cant wait for the LCDs to be back in stock so I can show the temp along with the lights

Bet your sorry you read the last line,

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: RGB Help Lesson 3

Post by adafruit_support_rick »

Will this do what you want?

Code: Select all

//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); delay(1000); digitalWrite(11, LOW); }
if (temperature < 75) { digitalWrite(11,LOW); delay(1000); digitalWrite(11, HIGH); }
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
}
Bet your sorry you read the last line,
Nah. This is what we do!

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

Post by mjpcarbon »

Rick, cant wait to try it tonight and report.
I was close to that.... but not quite I think I was only missing the brackets
thank you

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: RGB Help Lesson 3

Post by mjpcarbon »

PERFECT works exactly as I hoped.
Totally missed the { }
I didnt see them in other examples, hopefully I will be aware next time.
The brackets kind of turn the line into an equation

Again Awesome
thank you

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Starter Pack”