TinyCircuits

Add a pot to change timer of LED's

Add a pot to change timer of LED's
« on: April 28, 2013, 08:31:02 AM »
Add a pot to change timer of LED's, adjusting the pot resets the timer with out rewriting the sketch then loading it again and again to git  just the right speed.


/*
  For Loop Iteration
 
 Demonstrates the use of a for() loop.
 Lights multiple LEDs in sequence, then in reverse.
 
 The circuit:
 * LEDs from pins 0 through 12 to ground 5k pot at A0 adj timer
 
 created 2006
 by David A. Mellis
 modified 5 Jul 2009         
 by Tom Igoe
 modified Aug 2011 by Ayle
 http://www.arduino.cc/en/Tutorial/ForLoop
 */
        // Analog input pin that the potentiometer is attached to
        int potpin = A0;  // analog pin used to connect the potentiometer
        int val;    // variable to read the value from the analog pin
   int timer;   // The higher the number, the slower the timing.

   void setup() {
      // use a for loop to initialize each pin as an output:
   for (int thisPin = 0; thisPin < 13; thisPin++)  {
            pinMode(thisPin, OUTPUT);
      }
   }

   void loop() {
                val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
              timer = map(val, 0, 1023, 0, 254);     // scale it to use it with the timer (value between 0 and 255)

                // loop from the lowest pin to the highest:
      for (int thisPin = 0; thisPin < 13; thisPin++) {
         // turn the pin on:
         digitalWrite(thisPin, HIGH);   
         delay(timer);                 
         // turn the pin off:
         digitalWrite(thisPin, LOW);   
 
      }

      // loop from the highest pin to the lowest:
      for (int thisPin = 12; thisPin >= 0; thisPin--) {
         // turn the pin on:
         digitalWrite(thisPin, HIGH);
         delay(timer);
         // turn the pin off:
         digitalWrite(thisPin, LOW);
            
      }
   }

Re: Add a pot to change timer of LED's
« Reply #1 on: July 25, 2013, 02:21:05 PM »
Add a pot to change timer of LED's, adjusting the pot resets the timer with out rewriting the sketch then loading it again and again to git  just the right speed.


/*
  For Loop Iteration
 
 Demonstrates the use of a for() loop.
 Lights multiple led lighting in sequence, then in reverse.
 
 The circuit:
 * LEDs from pins 0 through 12 to ground 5k pot at A0 adj timer
 
 created 2006
 by David A. Mellis
 modified 5 Jul 2009         
 by Tom Igoe
 modified Aug 2011 by Ayle
 http://www.arduino.cc/en/Tutorial/ForLoop
 */
        // Analog input pin that the potentiometer is attached to
        int potpin = A0;  // analog pin used to connect the potentiometer
        int val;    // variable to read the value from the analog pin
   int timer;   // The higher the number, the slower the timing.

   void setup() {
      // use a for loop to initialize each pin as an output:
   for (int thisPin = 0; thisPin < 13; thisPin++)  {
            pinMode(thisPin, OUTPUT);
      }
   }

   void loop() {
                val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
              timer = map(val, 0, 1023, 0, 254);     // scale it to use it with the timer (value between 0 and 255)

                // loop from the lowest pin to the highest:
      for (int thisPin = 0; thisPin < 13; thisPin++) {
         // turn the pin on:
         digitalWrite(thisPin, HIGH);   
         delay(timer);                 
         // turn the pin off:
         digitalWrite(thisPin, LOW);   
 
      }

      // loop from the highest pin to the lowest:
      for (int thisPin = 12; thisPin >= 0; thisPin--) {
         // turn the pin on:
         digitalWrite(thisPin, HIGH);
         delay(timer);
         // turn the pin off:
         digitalWrite(thisPin, LOW);
            
      }
   }


Looks very effective code.. Surely will try it to change the timer.. Thanks for sharing
« Last Edit: July 26, 2013, 01:25:50 PM by RonnieBennett »