Simple Arduino Camera

Hey everyone,
I am trying to write code that will take 4 analog inputs from 4 photodiodes, read them into an array, and then output the value from the array through a pwm pin. The arduino then acts like a little camera, projecting whatever the light levels are on the photodiodes, to the LED’s I have hooked up. I have written code and It generally works pretty well, unless the light becomes very bright, or if I try to hook up a pull down resistor to my photodiodes. (Right now they are reverse biased and hooked directly to the analog inputs). Whenever the light becomes too bright, the LED’s stop lighting up at all, and will have little flickers of light randomly. The same thing happens when I try to hook up a pull down resistor. It also seems that when the light starts to get brighter the LED’s will pulse slowly, same with the pull down resistor. My computer isn’t letting me paste it for some strange reason so I have attached it to this post.

AnalogCamera.pde (1.04 KB)

Putting the call to output() inside the nested for loops seems harmless but pointless since you actually only intend to call it one time, once the loops have completed; why not put it after the loops?

I don't particularly trust the way you're manipulating the value returned from analogRead(), but I suspect the biggest problem is that use of i in output(). Did you mean to compare it to 0 instead of 10?

In any case, using a 2D array seems to add needless comple3xity. Why not have an array of 4 input pins and 4 analog values and walk through both arrays storing the raw values in a single loop? Then you can easily confirm that your sensors are returning sensible values, too. As it stands you don't do anything at all with the values except output them so you could simplify it even further and simply read the input value, calculate the output value and output the output value for each input. That only needs a couple of lines of code and would be much clearer.

The sketch would be more general if you configured the input and output pin numbers instead of assuming they were pins 0 .. 3.

Thanks for the reply, I got rid of the output() function and placed the output after the for() functions. I am using i = 13, and comparing i to ten because my pwm pins are 13, 12, 11 and 10. As well, I realized I could easily just use the analogWrite() function and output the analog values directly from the input, but I am still learning and am testing out how arrays work. I think my problem was with my power supply, I inadvertently disconnected a wire to the breadboard, but my arduino still had power. This also explains why my resistors wouldn't work. Thanks so much for reviewing my code and helping me clean it up! Much appreciated.