Go Down

Topic: AnalogWriteUno Sketch (Read 1 time) previous topic - next topic

dd_dent

While going through the lessons I came across the AnalogWriteMega sketch (http://arduino.cc/en/Tutorial/AnalogWriteMega).
I don't own an Arduino Mega, so I modified it for the Uno.
The result:
Quote

// This constant won't change. It's used to list
// the pins used:
const int ledPin[6] = { 3, 5, 6, 9, 10, 11};

void setup() {
  // set pins 3, 5, 6, 9, 10, 11 as outputs

  for (int thisPin =0; thisPin <= 5; thisPin++) {
    pinMode(ledPin[thisPin], OUTPUT);
  }
}

void loop() {
  // iterate over the pins:
  for (int thisPin =0; thisPin <= 5; thisPin++) {
    // fade the LED on thisPin from off to brightest:
    for (int brightness = 0; brightness < 255; brightness++) {
      analogWrite(ledPin[thisPin], brightness);
      delay(2);
    } 
    // fade the LED on thisPin from brithstest to off:
    for (int brightness = 255; brightness >= 0; brightness--) {
      analogWrite(ledPin[thisPin], brightness);
      delay(2);
    } 
    // pause between LEDs:
    delay(100);
  }
}




It functions as intended, and It occurred to me that maybe someone would like to integrate this into the learning section?
Is this good practice? Is it redundant?
If the answers are yes and no, can someone direct me on how create the schematic and circuit diagram?

Go Up