c

c

You have a lot going on in that code that doesn't make any sense without a schematic.

What is more are you trying to light up LEDs by using a multiplexer? That is a silly thing to do, was it your idea or did you get it from a web page?

i have this code it doesn't work

That doesn't cut it in electronics, you have to say exactly what it does and how it is different to what you expected.

What you are doing is a typical beginners mistake in trying to do too much at once.
The way you code is to do a small piece, test it and then move on to the next bit.

I would try to just write a program that sets a fixed number of LEDs. Write that as a function that you pass a number to defining what LEDs are lit.

The write a function that increments a variable when your cup covers a sensor and prints it out. In the end you don't need to keep this print statement but it shows you your sensor function is correct. Then use these two functions to build what you want to do.

I find your coding stile difficult to follow and a bit turgid. When you need to write the same statement over and over, you use a for loop and an array. For example:-

pin[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41};
for(int i = 0; i<20; i++){
pinMode[pin[i]] = OUTPUT;
}

Also why:-

//lees de waarde op de uitgang SIG
  int val = analogRead(SIG_pin2);
 
  return val;

Why not just:-

//lees de waarde op de uitgang SIG
  return analogRead(SIG_pin2);

I would still like to see a schematic.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.