Well I think a need to reconsider my priorities, let's put aside the modular thing for the moment.
I'm trying to control the brightness of two LEDs using one potentiometer each, through a CD4051BCN mux (they will be 8 when I will understand what's wrong). I have attached the schematic (I hope I did it right) and here's the code
const int analogPin = A0;
int r0 = 0;
int r1 = 0;
int r2 = 0;
int count = 0;
int ledPin[2]={10, 11};
unsigned int analRead[2] = {0,0};
unsigned int analValue[2] = {0,0};
int threshold = 2;
void setup() {
pinMode(2, OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
for (count=0; count<2; count++) {
r0 = bitRead(count,0);
r1 = bitRead(count,1);
r2 = bitRead(count,2);
digitalWrite(2,r0);
digitalWrite(3,r1);
digitalWrite(4,r2);
analRead[count] = analogRead(analogPin);
if (abs(analRead[count] - analValue[count]) >= 2) {
analogWrite(ledPin[count], analRead[count]);
analValue[count] = analRead[count];
}
}
}
Can someone please help me?
