Created
June 18, 2013 00:02
Revisions
-
pdesantis created this gist
Jun 18, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ // Arduino Workshop Project 3 // PWM int d = 5; // d is used for time delay const int number_of_pins = 5; // the number of output pins int pins[number_of_pins] = {3, 5, 6, 9, 10}; // an array storing each output pin // Sets the proper pins to output mode void setup() { for (int i = 0; i < number_of_pins; i++) { pinMode(pins[i], OUTPUT); } } void loop() { // Loop through each pin in pins array, pulsing them one at a time for (int i = 0; i < number_of_pins; i++) { pulsePin(pins[i]); } // Pause for 200 milliseconds delay(200); } // ******* Helper methods ******* // Function: lightUpPin // Write analog values 0 to 255 to the specified pin // Parameter: pin - the pin to light up void lightUpPin(int pin) { for ( int a = 0 ; a < 256 ; a++ ) { analogWrite(pin, a); delay(d); } } // Function: lightUpPin // Write analog values 255 to 0 to the specified pin // Parameter: pin - the pin to dim void dimPin(int pin) { for ( int a = 255 ; a >= 0 ; a-- ) { analogWrite(pin, a); delay(d); } } // Function: pulsePin // Pulses a pin from analog 0 to 255 and back to 0 // Parameter: pin - the pin to pulse void pulsePin(int pin) { lightUpPin(pin); dimPin(pin); }