Author Topic: Led dimmen  (Read 13906 times)

SeviT

  • Newbie
  • *
  • Posts: 42
  • Karma: +1/-0
Led dimmen
« on: October 24, 2012, 09:29:23 PM »
Hallo

Ich habe ein problme.

Ich habe ein arduino uno r3. bin anfänger und habe schon recht erfolge bis jetzt, doch jetzt stecke ich fest  :o

mein projekt

ich habe zwei led's jedes kann grün und rot leuchten
ich will die rote led anschalten und dann dimmen und während der rote chip dimmt den grünen immer heller machen.

kann mir da jemand helfen

danke schon im voraus

Sevi

MathiasW

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 614
  • Karma: +13/-0
    • my Arduino page
Re: Led dimmen
« Reply #1 on: October 25, 2012, 09:24:24 AM »
Salut Sevi,

in der Tutorialsection von arduino.cc gibt es ein Beispiel, welches wahrscheinlich passen sollte:
http://www.arduino.cc/en/Tutorial/DimmingLEDs
Code: [Select]
/*
* Code for cross-fading 3 LEDs, red, green and blue, or one tri-color LED, using PWM
* The program cross-fades slowly from red to green, green to blue, and blue to red
* The debugging code assumes Arduino 0004, as it uses the new Serial.begin()-style functions
* Clay Shirky <clay.shirky@nyu.edu>
*/

// Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11

// Program variables
int redVal   = 255; // Variables to store the values to send to the pins
int greenVal = 1;   // Initial values are Red full, Green and Blue off
int blueVal  = 1;

int i = 0;     // Loop counter   
int wait = 50; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 0; // DEBUG counter; if set to 1, will write values back via serial

void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  if (DEBUG) {           // If we want to see the pin values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput on 0004 style
  }
}

// Main program
void loop()
{
  i += 1;      // Increment counter
  if (i < 255) // First phase of fades
  {
    redVal   -= 1; // Red down
    greenVal += 1; // Green up
    blueVal   = 1; // Blue low
  }
  else if (i < 509) // Second phase of fades
  {
    redVal    = 1; // Red low
    greenVal -= 1; // Green down
    blueVal  += 1; // Blue up
  }
  else if (i < 763) // Third phase of fades
  {
    redVal  += 1; // Red up
    greenVal = 1; // Green low
    blueVal -= 1; // Blue down
  }
  else // Re-set the counter, and start the fades again
  {
    i = 1;
  } 

  analogWrite(redPin,   redVal);   // Write current values to LED pins
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin,  blueVal); 

  if (DEBUG) { // If we want to read the output
    DEBUG += 1;     // Increment the DEBUG counter
    if (DEBUG > 10) // Print every 10 loops
    {
      DEBUG = 1;     // Reset the counter

      Serial.print(i);       // Serial commands in 0004 style
      Serial.print("\t");    // Print a tab
      Serial.print("R:");    // Indicate that output is red value
      Serial.print(redVal);  // Print red value
      Serial.print("\t");    // Print a tab
      Serial.print("G:");    // Repeat for green and blue...
      Serial.print(greenVal);
      Serial.print("\t");   
      Serial.print("B:");   
      Serial.println(blueVal); // println, to end with a carriage return
    }
  }
  delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}

Hab ich das richtig verstanden?

Ciao, Mathias

SeviT

  • Newbie
  • *
  • Posts: 42
  • Karma: +1/-0
Re: Led dimmen
« Reply #2 on: October 25, 2012, 05:35:57 PM »
Hallo

Vielen dank ja genau das wollte ich  :D
jetzt kann ich weitermachen  :)

Sevi

MathiasW

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 614
  • Karma: +13/-0
    • my Arduino page
Re: Led dimmen
« Reply #3 on: October 25, 2012, 06:09:43 PM »
Salut Sevi,

freut mich!
Eine tolle Quelle, um den Arduino mit Beispielen zu verstehen ist:
http://tronixstuff.wordpress.com/tutorials/
Desweiteren rate ich Dir, ein Einstiegsbuch zu kaufen, zum einen das exzellente Parxisbuch http://www.amazon.de/Arduino-Praxiseinstieg-Behandelt-mitp-Professional/dp/3826691164/ref=sr_1_1?s=books&ie=UTF8&qid=1351181288&sr=1-1 und zum andern das Buch von Erik Bartmann http://www.amazon.de/OReillys-basics-elektronische-Arduino-entdecken/dp/3897213192/ref=sr_1_3?s=books&ie=UTF8&qid=1351181288&sr=1-3

Ciao, Mathias

SeviT

  • Newbie
  • *
  • Posts: 42
  • Karma: +1/-0
Re: Led dimmen
« Reply #4 on: October 25, 2012, 07:06:21 PM »
Hallo

danke für die vorschläge  :)
das buch werde ich gleich kaufen

sevi