Pages: [1]   Go Down
Author Topic: 1 LED 2 pots  (Read 994 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Arduino newb here.
Can anyone tell me if its possible to have 1 LED controlled by 2 pots, so that one pot controls the blink rate (Speed) and another that controls the LED intensity (Depth). I have been able to do the first easy enough by following the helpfull example titled AnalogueInput - http://arduino.cc/en/Tutorial/AnalogInput

Also on my breadboard I can just add the 2nd pot and bleed current off the LED to ground.

But how would one do this with the Arduino alone. Also read somewhere else on this forum that there are stages of brightness in an LED - can someone explain that a bit more?? And possibly how I could use that info in my sketch to really fine tune the depth/intensity pot?

I am using the Arduino in place of a 555 timer chip in an very simple analogue tremolo effects pedal for guitar that includes an homemade optocoupler (LDR and LED). Basically, I have a passive side on my beadboard: input jack>LDR>output jack - on the other side of the breadboard its active, which has the +-power wires, and a wire from pin (9) >220R resistor>LED. When I put cap over the board (as in hat not capacitor lol smiley-wink) the blinking LED/LDR allows the guitar signal to pass through with fairly pleasing tremolo sound.

I have really only had the board a couple of days and no code experience and am doing this as a learning excercise. Any info about how to approach coding this properly or where to find that info on the Arduino site - would be much appreciated.
cheers
Steve
« Last Edit: March 07, 2011, 07:26:27 am by dogbox » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Put your LED on one of the PWM pins and use analogWrite to control the intensity of the ON time.
Very simplest code could be something like:
Code:
void loop ()
{
  analogWrite (LEDpin, analogRead (potPin0) / 4);
  delay (analogRead (potPin1));
  analogWrite (LEDpin, 0);
  delay (analogRead (potPin1));
}
« Last Edit: March 07, 2011, 07:44:02 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Put your LED on one of the PWM pins and use analogWrite to control the intensity of the ON time.
Very simplest code could be something like:
Code:
void loop ()
{
  analogWrite (LEDpin, analogRead (potPin0) / 4);
  delay (analogRead (potPin1));
  analogWrite (LEDpin, 0);
  delay (analogRead (potPin1));
}

Ok thanks very much

so my basic code now looks like this and works perfectly in my Trem-O-duino pedal. smiley

Code:
int potPin1 = A1;
int potPin0 = A0;
int ledPin = 9;
void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); 
}


void loop ()
{
  analogWrite (ledPin, analogRead (potPin0) / 4);
  delay (analogRead (potPin1));
  analogWrite (ledPin, 0);
  delay (analogRead (potPin1));
}

Hoping you can explain what the "4" represents??

thanks very much for this. I'm loving Arduino - I've got lot of reading to do...
Logged

Gatineau, Qu
Offline Offline
Jr. Member
**
Karma: 1
Posts: 94
Did you Arduino today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

analogRead (potPin0) is reading your potPin0 and will return a value between 0 and 1023.
analogWrite is expecting a value between 0 and 255.
So the / 4 is there to dived (by 4) the value returned by analogRead so it is usable by analogWrite.

Read up on it at this page: http://arduino.cc/en/Reference/HomePage




Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, there's no need to set the pinMode of a PWM pin if that's what you're going to use it for - the analogWrite takes care of it.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: