Hi,
I set up a arduino nano with a cd4067 multiplexer. (Analog input A0 is POSCV)
Now I want to output a number from 0-15 for the Pin that reads the highest number. (whenever one of them is higher than 250).
(eg. if address pin 13 on the 4067 has the highest value of 800 and all other pins are lower, set the "led" to 13)
For now, the code looks like this, but the int "k" only gives me 1.
#define POSCV A0
int temp = 0;
int led = 17;
int k = 0;
int m = 0;
int addressPins[] = {6, 7, 8, 9};
void setup ()
{
pinMode (POSCV, INPUT);
Serial.begin(9600);
Wire.begin();
for (int m = 0; m <= 3; m++) {
pinMode(addressPins[m], OUTPUT);
}
}
void loop ()
{
for (int k = 0; k <= 15; k++) {
for (int m = 0; m <= 3; m++) {
digitalWrite(addressPins[m], bitRead(k, m));
}
}
temp = analogRead(POSCV);
if (temp < 250)
{
//nothing
}
else if (temp >= 250)
{
bitRead(k,m);
if (k == 15)
{
led = 15;
}
else if(k == 14)
{
led = 14;
}
else if(k == 13)
{
led = 13;
//.... [continues until k == 0]
I guess there is another way to do this which i can't seem to find.
Can someone help me?