Sharp GP2D12 sensor & array of LEDs....

hello noob here,

I am able to use the Sharp GP2D12 sensor to turn on LEDs & motors.

I’m wondering if it’s possible to use the sensor to control an array of LEDs. For example, the pattern of the LEDs movie faster when close to the sensor and than slow down when not.

I tried combining the code for the sensor w/ the array code from the Arduino Learning page ( but seem to be getting errors. not that good w/ coding yet.

any thoughts or feedback on this would be greatly appreciated.

Yes what you want to do is perfectly possible if you write the code correctly.
Don’t use the delay() function as this ties up the processor and you can’t do anything else.

Basically write it as a loop that has a variable, let’s say nextChange that contains the value of the millis() count when the next change should happen. Then each time round the loop check this wit a :-
if(nextChange > millis()) {
// do the next light change
nextChange = millis() + 10 // this will do the change every 10mS