So I have just started my first real project and have run into a small snag. After running some test builds on 123D Circuits, I finally got my wiring done, and code built. On the website it works like a charm, so I thought putting it onto the real thing would be simple, I was wrong. Once I wired everything up and uploaded the code I noticed that my pots were not controlling the RGB LED like they did in the 123D. All of my Pots work, as do the wires (I moved them around just to check). So I tried a Serial Print, and saw that the only one that would read was my Red Pot, up to a point. Once the Red was high enough the Green Pot would start to bleed in when I turn it on, but would not work alone and had to have the Red almost full to get anything from it.
Here is my code. I'm not sure if it is something wrong in it that is causing the issue, or if it is something else on the breadboard/Arduino.
//RGB Potentiometers
const int reddile = A0;
const int gredile = A1;
const int bludile = A2;
//Randome color gen button
const int rando = 2;
//RGB LED
const int red = 3;
const int gre = 5;
const int blu = 6;
//Togle switch between ran button and Pot
const int diletorando = 4;
int buttonState = 0;
long randNumber;
void setup()
{
Serial.begin(9600);
pinMode(reddile, INPUT);
pinMode(gredile, INPUT);
pinMode(bludile, INPUT);
pinMode(rando, INPUT);
pinMode(red, OUTPUT);
pinMode(gre, OUTPUT);
pinMode(blu, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
//Switch from Pots to random number
if (digitalRead(diletorando) == LOW)
{
buttonState = digitalRead(rando);
if (buttonState == LOW)
{
//While button is pressed make first random number for the RGBs
digitalWrite(red, LOW);
digitalWrite(gre, LOW);
digitalWrite(blu, LOW);
}
else
{
//After release generate a second random number for the RGBs
digitalWrite(red, randNumber = random(255));
digitalWrite(gre, randNumber = random(255));
digitalWrite(blu, randNumber = random(255));
}
}
else
{
//Pots to RGB signals
int redread = analogRead(reddile);
int greread = analogRead(gredile);
int bluread = analogRead(bludile);
int mapred = map(redread,0,1023,255,0);
int mapgre = map(greread,0,1023,255,0);
int mapblu = map(bluread,0,1023,255,0);
analogWrite(red, mapred);
analogWrite(gre, mapgre);
analogWrite(blu, mapblu);
Serial.println(redread);
Serial.println(greread);
Serial.println(bluread);
}
}