Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 09, 2013, 07:37:21 am
Ha! Well, to be fair, I have been toying around with ways to manipulate/gate circuits & audio for a few years now and I probably went through the agony and frustration stage two years back. Now it's just enjoyment and pleasure without a deadline looming.

I will say that I do have to sort out doing this without there being the delays present and that's got me confused/lost. I'm not quite sure how I can go about doing that with these three settings. I'm not totally sure how to nest all of this within the programming to get it to work properly.
2  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 08, 2013, 04:16:40 pm
Thanks for the help with this, it's greatly appreciated. My expectations for how it should behave are really... well, minimal, I'm more curious to see where it can be different and odd. I know that my interests aren't in having a highly tuned envelope generation system... but, I'd like to see it useful in a standalone circuit I'm hacking again and hopefully with more nuance.

With that said, I did a bit of toying with some other code I'd looked at in the past, and have found a way to control the Attack, Sustain and Decay of the LED using 3 potentiometers. I've included the code below, but admittedly, I'm using delays in it and I'd love to be able to sort out not having that be the case. In part because I'd like to be controlling other LEDs with some different, but related code that's checking in on the overall time of the three parameters in this section of code.

Code:
int ledPin = 9;    // LED connected to digital pin 11
int potPin = 0; //fade in pot
int potPin1 = 5; //sustain pot
int potPin2 = 3; //fade out pot
int val; //fade in duration
int val1; //sustain or hold duration
int val2; //fade out duration
void setup()  {
}

void loop()  {
{
  val = analogRead(potPin);
  val = map(val, 0, 1023, 10, 1);
 
  val1 = analogRead(potPin1);
  val1 = map(val1, 0, 1023, 10, 1);
 
  val2 = analogRead(potPin2);
  val2 = map(val2, 0, 1023, 0, 5000);
}

  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
  analogWrite(ledPin, fadeValue);       
  delay(val);   
  }
       
  delay(val2); 

  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1) {
  analogWrite(ledPin, fadeValue);
  delay(val1);                           
  }
}
3  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 08, 2013, 01:36:29 pm
I'll give that a try to see what it looks like. I'd like to have the total time be variable since I'm intending this to eventually run an optocoupler that is controlling the behaviors of an audio circuit.
4  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 08, 2013, 12:03:59 pm
I was thinking of having it ramp up to 1023 rather than "any value". In the programming I have "sensorValue2" as the total period, while I have sustain (or on) as "sensorValue".

I have been trying to figure out what the equation would need to be in the if/else section so that it would look at the "total period" duration of sensorValue2, read the sensorValue adusted to sensorValue2's total range to get the "on" period and then have the decay (or off) be the result of subtracting sensorValue from sensorValue2.

So far I appear to be doing some things that aren't working.
5  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 08, 2013, 11:05:49 am
Yes... exactly.
6  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 08, 2013, 10:10:43 am
So,

Having removed the delay, I'm able to control the overall range of pulse with pot #2 while pot #1 sets the actual duration of the pulse. That said, I'm still scratching my head as to how to make pot #1 control what part of pot #2's duration equals time on and time off.

Code:
const int ledPin =  9;      // the number of the LED pin

int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int sensorPin2 = A5;
int sensorValue2 = 0;

long interval = sensorValue; // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);     
}

void loop()
{
    sensorValue = analogRead(sensorPin);
   sensorValue = map(sensorValue, 0, 1023, 0, sensorValue2);
 
  sensorValue2 = analogRead(sensorPin2); 
   sensorValue2 = map(sensorValue2, 0, 1023, 0, 5000); 
   
  unsigned long currentMillis = millis();
 
{
  if(currentMillis - previousMillis > sensorValue) {
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(ledPin, ledState);
    }
   
  }
 
}
7  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 08, 2013, 09:27:46 am
I have been working on the other part of the programming... which is commented out in the below bit of code, but basically, it takes a range as set by pot #2, maps pot #1s range to that duration for fade in, then subtracts that duration from pot #2s duration to get the fade out. I am trying to understand how to then take that from a High/Low to a Fade in/out control, but am running into problems with it. Any suggestions would be wonderful

Code:
int sensorPin = A0;   
int sensorPin2 = A5;
int ledPin = 9;     
int sensorValue = 0; 
int sensorValue2 = 0;
int brightness = 0;   
int fadeAmount = 5;   

void setup() {
 
  pinMode(ledPin, OUTPUT); 
}

void loop() {
  analogWrite(ledPin, brightness);   
  sensorValue = analogRead(sensorPin); 
  sensorValue2 = analogRead(sensorPin2); 
  sensorValue2 = map(sensorValue2, 0, 1023, 0, 5000);   
  sensorValue = map(sensorValue, 0, 1023, 0, sensorValue2);
 
brightness = brightness + fadeAmount;
  if (brightness == 0 || brightness >= sensorValue) {
  fadeAmount = -fadeAmount ;
}     

  delay(sensorValue);       
 
 
//  digitalWrite(ledPin, HIGH); 
//  delay(sensorValue);         
       
//  digitalWrite(ledPin, LOW);   

 // delay(sensorValue2-sensorValue);                 
}
8  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 05, 2013, 06:47:12 pm
The second option, where you switch the sensorvalue in for 255 is getting me closer... I think I need to sort out the second part of this idea, which is to insert a second pot that has a mapped range of 0 - 1023 to something like 0 - 10 seconds, while the first pot (the one I'm working with now) splits that time span to provide the fade in/out percentages/information.

I'll try to post further code tonight.
9  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 05, 2013, 06:20:56 pm
I'm going to try variations on both those suggestions... though I was thinking perhaps something like,

Get fade in delay, subtract that from 1023 and then get fade out delay from the remaining part of 1023...

So if fade in delay = 200, fade out delay would be.... 1023 -(fade in delay) = 823

Something like that. I have one more stage of complications after that, but I want to sort this out first... then move on to the final part.
10  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 05, 2013, 04:11:41 pm
So, for example... with this, I have the fade occurring properly in relationship to a potentiometer... but what I am wondering is if there is a way to control where the peak of the fade occurs in the loop. So that, if the pot is at 200, the peak occurs earlier, with a longer fade out, or if the pot is at 1000 it peaks at the end of the loop.

Code:

int led = 9;         
int brightness = 0;   
int fadeAmount = 5;   
const int analogInPin = A0;
int sensorValue = 0;


void setup ()
  {

    pinMode(led, OUTPUT);
  }  // end of setup

void loop ()
  {

 analogWrite(led, brightness);   
int sensorValue = analogRead(A0);
sensorValue = map(sensorValue, 0, 1023, 0, 30);
 
  brightness = brightness + fadeAmount;

 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }     

  delay(sensorValue);                           


}
11  Using Arduino / Project Guidance / Re: Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 05, 2013, 02:56:08 pm
I've used the digital blink on/off with duration of pulse set by potentiometer reading for a long time. And I've done a bit with using the analog control of LED with potentiometer for controlling the level of lighting, but combining the two, no.
12  Using Arduino / Project Guidance / Controlling Fade In/Out duration/peak of LED using Potentiometer on: September 05, 2013, 02:49:43 pm
I have been thinking about this for awhile and have hunted through the forums but can't seem to locate any information on the idea I have. I would like to be able to control the fade in/out behavior of LEDs w/PWM where a potentiometer could be used to set where the peak within an LED's "on" period would be.

I've previously just used the digital on/off, high/low settings for LEDs and am hoping to be able to move away from that use PWM. Unfortunately I can't seem to sort out how to go about this. Basically I'm looking to create an envelope of a sort for the LED.
13  Using Arduino / LEDs and Multiplexing / Re: Using one Potentiometer to Control Multiple LEDs at different rates on: August 29, 2011, 09:13:28 am
Thanks for the response. I posted and then realized I could do something like that... but wasn't quite positive about the proof of concept etc... the snag seems to be though that they aren't quite hitting in sync with one another... so that it's doing the .5 slightly off from the 1.0, which I don't quite understand why that'd be happening. Do you think there's a way to get them to lock together tightly? Or is there always going to be this slippage?
14  Using Arduino / LEDs and Multiplexing / Using one Potentiometer to Control Multiple LEDs at different rates on: August 28, 2011, 10:47:23 pm
So I've been doing some preliminary research/testing and can't seem to quite sort out how to take a single potentiometer reading and take the sensor reading and output to, say, three LEDs. My problem lies in trying to understand how I'd be able to output the analog reading to one LED as you normally would with the LED blink programming, while controlling another LED at double that same analog reading, while outputting to a third LED at half speed. I'm using this as my starting point.... but can't seem to get my head around how to sort out the next steps. Any help would be amazing and thank you in advance for any advice as I work through this. I'm excited to see if this is possible.

const int ledPin =  2;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
long interval = sensorValue; // interval at which to blink (milliseconds)


void setup() {
  pinMode(ledPin, OUTPUT);     
}

void loop()
{
   sensorValue = analogRead(sensorPin);
  unsigned long currentMillis = millis();

{
  if(currentMillis - previousMillis > sensorValue) {
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(ledPin, ledState);
   
    }
  }
}
15  Using Arduino / LEDs and Multiplexing / Re: LED Sequencer with 4017 chip on: February 28, 2011, 04:24:16 pm
speed isn't really that critical, i've built similar things out of just 4017's in the past and been more than content with it, just would like to step things up and have the ability to manipulate behavior of the circuit in the future. I'll wire it up this evening and see if I can get the results I'm after, otherwise I'll start taking a look at your other suggestions and go from there. thanks again.
Pages: [1] 2 3 4