DISCLAIMER: Total noob ![]()
If this is in the wrong forum, I'm really sorry.
My girlfriend got me an arduino duemilanove kit over christmas, and I've been playing around with sample codes and whatnot. It is really getting interesting ;D
I make a lot of analog circuits for music stuff, so I've been trying to come up with a project to use my new digital fun chip with. I've decided a digital wah would be fun (digital pot control, that is), and I'm having two problems with completeing it.
The first is fading between 2 LED's. The pot in the wah enclosure can be used into the arduino as a voltage divider with the 5v, so I am trying to set it up so that as you move the rocker forward, the red LED fades in (blue fading out) and as you move it back, the blue LED fades in (as well as red fading out).
The second part of this project is to have the same analog pot control a digital pot at the same time, but I need to get this LED part done first ![]()
So, I took the fading between 3 LED code and modified it a bit to get it to fade between 2 LED's. It is fading the blue LED all the way out, then at the middle of the pot, the blue LED is dimmed all the way, and the red begins to fade in. What I want ( ::)) it to do is to have each LED brightest at either end of the sweep, but have them fade in and out at the same time, not one then the other.
Here is the code I'm using
// INPUT: Potentiometer should be connected to 5V and GND
int potPin = 3; // Potentiometer output connected to analog pin 3
int potVal = 0; // Variable to store the input from the potentiometer
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED's cathodes should be connected to digital GND
int redPin = 9; // Red LED, connected to digital pin 9
int bluPin = 11; // Blue LED, connected to digital pin 11
// Program variables
int redVal = 0; // Variables to store the values to send to the pins
int bluVal = 0;
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(bluPin, OUTPUT);
if (DEBUG) { // If we want to see the pin values for debugging...
Serial.begin(9600); // ...set up the serial ouput in 0004 format
}
}
// Main program
void loop()
{
potVal = analogRead(potPin); // read the potentiometer value at the input pin
if (potVal < 511) // Lowest third of the potentiometer's range (0-340)
{
potVal = (potVal * 2) / 4; // Normalize to 0-255
redVal = 256 - potVal; // Red from full to off
bluVal = 1; // Blue off
}
else if (potVal < 1023) // Middle third of potentiometer's range (341-681)
{
potVal = ( (potVal-1023) * 2) / 4; // Normalize to 0-255
redVal = 1; // Red off
bluVal = potVal; // Blue from off to full
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(bluPin, bluVal);
if (DEBUG) { // If we want to read the output
DEBUG += 1; // Increment the DEBUG counter
if (DEBUG > 100) // Print every hundred loops
{
DEBUG = 1; // Reset the counter
// Serial output using 0004-style functions
Serial.print("R:"); // Indicate that output is red value
Serial.print(redVal); // Print red value
Serial.print("\t"); // Print a tab
Serial.print("B:");
Serial.println(bluVal); // println, to end with a carriage return
}
}
}
My brain is totally fried. If anyone has any input on how to modify this code, I would much appreciate it. Also, if there is an easy control code that I haven't found, that would be a big help, if this way isn't the best way to do it.
Thanks a lot ![]()