0

RGB Help Lesson 3
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: RGB Help Lesson 3

by adafruit_support_rick on Fri Mar 14, 2014 9:39 am

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.

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

Re: RGB Help Lesson 3

by mjpcarbon on Fri Mar 14, 2014 10:02 am

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

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

Re: RGB Help Lesson 3

by adafruit_support_rick on Fri Mar 14, 2014 10:10 am

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

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

Re: RGB Help Lesson 3

by mjpcarbon on Fri Mar 14, 2014 10:17 am

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);

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

Re: RGB Help Lesson 3

by adafruit_support_rick on Fri Mar 14, 2014 11:18 am

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.

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

Re: RGB Help Lesson 3

by mjpcarbon on Fri Mar 14, 2014 11:33 am

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,

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

Re: RGB Help Lesson 3

by adafruit_support_rick on Fri Mar 14, 2014 11:57 am

Will this do what you want?
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); 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!

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

Re: RGB Help Lesson 3

by mjpcarbon on Fri Mar 14, 2014 12:07 pm

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

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

Re: RGB Help Lesson 3

by mjpcarbon on Fri Mar 14, 2014 5:40 pm

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

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

Please be positive and constructive with your questions and comments.