Go Down

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


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:

// 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);
    // fade the LED on thisPin from brithstest to off:
    for (int brightness = 255; brightness >= 0; brightness--) {
      analogWrite(ledPin[thisPin], brightness);
    // pause between LEDs:

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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131