please help me with this logic :/

ok so im doin this table project right now with a friend.
it consists of 20 leds. atm im working on just controlling 10 leds with 10 ir sensors and emiters. we can get it to run with just a single led/ir/em but we want it to sense ever sensor. so i decided to use arrays but we end up with so much problems that way and im not sure what im doing wrong. heres the latest thing i’ve written.

i have other scripts that potentialy work but im just not sure. i’ll show them if any of you would like to see them too.
(im a software designer not a programmer for this stuff so sorry bout this)

#include <Tlc5940.h>
#include <tlc_animations.h>
#include <tlc_config.h>
#include <tlc_progmem_utils.h>
#include <tlc_shifts.h>


const int sensorPin[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9};    
const int SPT = sensorPin[9];



// variables:
int i =0;
int sensorValue[] = {0,0,0,0,0,0,0,0,0,0};         // the sensor value
int SV=0;
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int ledPin[] = {0,1,2,3,4,5,6,7,8,9};

void setup() {
  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds 
  while (millis() < 5000) {
    SV = analogRead(SPT);

    // record the maximum sensor value
    if (SV > sensorMax) {
      sensorMax = SV;
    }

    // record the minimum sensor value
    if (SV < sensorMin) {
      sensorMin = SV;
    }

  }
  
    // read the sensor:
    for(i=0;i<10;i++) {
  sensorValue[i] = analogRead(sensorPin[i]);
 // apply the calibration to the sensor reading
  sensorValue[i] = map(SV, sensorMin, sensorMax, 0, 1024);
 // in case the sensor value is outside the range seen during calibration
  sensorValue[i] = constrain(SV, 0, 1024); }
 // signal the end of the calibration period
  digitalWrite(13, LOW);
i=0;
Tlc.init();
} 

void loop() {
 int x = 3;
 
  // fade the LED using the calibrated value:
 
  while(x=3) {
    for(i=0;i<10;i++) {
  analogRead(sensorPin[i]);
  Tlc.set(ledPin[i], sensorValue[i]); 
  Tlc.update();
         } i=0;   }

}

like i said that was the latest one i’ve written. though previously i wrote a libarry and did something like this

  int grncon(int a[10],int c[10],int b,int d[10],int e[10],int f[10]) {

  // read the sensor:
	for(b=0;b<9;b++){
		a[b]= analogRead(c[b]); }
  // apply the calibration to the sensor reading
	for(b=0;b<9;b++) {
		a[b] = map(a[b], d[b],e[b], 0, 4095); }but not otherwise. anyhelp would be
    // in case the sensor value is outside the range seen during calibration
    for(b=0;b<9;b++) {	
	a[b] = constrain(a[b], 0, 4095); }
    // fade the LED using the calibrated value:
	for(b=0;b<9;b++) {
		Tlc.set(f[b], a[b]); }
  }

that was in a libarry i had been writing for the table it self. but it didnt seem to run. it would if i didnt use array but this would be far too much to simply type out.

if anyone can fix this problem or guide me or even just show me the right way i would greatly apriciate it. thank you!

Difficult to see what you're trying to do; you have an infinite while loop, and an analogRead you ignore the result of.

  sensorValue[i] = map(SV, sensorMin, sensorMax, 0, 1024);

Why are you mapping SV, instead of sensorValue[ i ]?

Why are you mapping, anyway?

  sensorValue[i] = constrain(SV, 0, 1024); }

Same questions.

  analogRead(sensorPin[i]);
  Tlc.set(ledPin[i], sensorValue[i]);

Probably work better if you didn't discard the value read from the sensor.

=__=.

the reason it is an infinite is because it will constantly check the status of the sensors. here it is revised sorry bout that.

while(x=3) {
for(i=0;i<10;i++) {
sensorValue = analogRead(sensorPin*);*
Tlc.set(ledPin_, sensorValue*);
Tlc.update();
} i=0; }*

i want it to be infinite for right now unless i say so._

nooo i want sv lol. here i’ll post the whole thing sorry im being so dificult

#include <Tlc5940.h>
#include <tlc_animations.h>
#include <tlc_config.h>
#include <tlc_progmem_utils.h>
#include <tlc_shifts.h>


const int sensorPin[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9};    
const int SPT = sensorPin[9];



// variables:
int i =0;
int sensorValue[] = {0,0,0,0,0,0,0,0,0,0};         // the sensor value
int SV=0;
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int ledPin[] = {0,1,2,3,4,5,6,7,8,9};

void setup() {
  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds 
  while (millis() < 5000) {
    SV = analogRead(SPT);

    // record the maximum sensor value
    if (SV > sensorMax) {
      sensorMax = SV;
    }

    // record the minimum sensor value
    if (SV < sensorMin) {
      sensorMin = SV;
    }

  }
  
    // read the sensor:
    for(i=0;i<10;i++) {
  sensorValue[i] = analogRead(sensorPin[i]);
 // apply the calibration to the sensor reading
  sensorValue[i] = map(SV, sensorMin, sensorMax, 0, 1024);
 // in case the sensor value is outside the range seen during calibration
  sensorValue[i] = constrain(SV, 0, 1024); }
 // signal the end of the calibration period
  digitalWrite(13, LOW);
i=0;
Tlc.init();
} 

void loop() {
 int x = 3;
 
  // fade the LED using the calibrated value:
 
  while(x=3) {
    for(i=0;i<10;i++) {
  sensorValue[i] = analogRead(sensorPin[i]);
  Tlc.set(ledPin[i], sensorValue[i]); 
  Tlc.update();
         } i=0;   }

}

What was the purpose of all that mapping and constraining, if you are sending raw sensor data to the TLC?

basicly whats happening is im taking the value from ONE sensor value and using that to calibrate EVERY sensor. then they will be individualy controlled with sensorValue. whitch in turn the array of sensorvalues are all calibrated to sv.

the mapping just helps calibrate. or i thought it did. is it un nececcary?.

for(i=0;i<10;i++) {
sensorValue[ i ] = analogRead(sensorPin[ i ]);

Read a value from a sensor.

// apply the calibration to the sensor reading
sensorValue[ i ] = map(SV, sensorMin, sensorMax, 0, 1024);

Throw that value away, and replace it with the last value read from the 10th sensor, mapped to a possibly larger range.

// in case the sensor value is outside the range seen during calibration
sensorValue[ i ] = constrain(SV, 0, 1024); }

Then throw that mapped value away, and replace it with the last reading from the 10th sensor (since that reading will always be within the specified range.

All this “calibration” is doing what for you?

Also you don't have to do the TLC.update until you have put all the sensor values in.

well when the table calibrates it finds its "area" like its 0 line. basicly the mapping and constrain functions are used to gived mapping values and constrain the pins to those values so when in the loop function the have the mapped data to read from.

my main concern is getting the led's to be controlled by multiple ir sensors with an array instead of just typing it. if i can get that then everything would be perfect.

oh yes i know but i constantly update the led's to get a quick result. though if it causes problems i'd gladly take it out.

Well it gives you a much slower result. The set command takes no time at all but it is the update that shifts all the data out.

if i can get that then everything would be perfect.

So you are not worried that you are not calibrating it correctly then.

thank you verry much for telling me that update does that! :).

and yes i am.

i use the if statements at the top to calibrate a sensor to its 0 line. then constrain all sensorsvalues to that one calibrated pin. and ive made it so sv is the value of the last led calibrated like you said.

BUMP.

please seomone help me.

if you can atleast answer this. "how do i control multiple outputs with multiple inputs using an array??

just showing me how it would be done would be enough to spark everything else i need. i really need to finish this project soon

It's not at all clear what you're trying to do with an array, although you clearly have one working in loop, albeit where a single variable would do just as well so far since you aren't ever using the contents of the array again after pushing it out to the tlc. You say you have the code working for a single led; it might make it clearer if you could post that, or better still one that works for two by 'just typing it'.

BUMP? Come on, now. Some of us have to work, too. Or, in my case, travel home after work.

basicly the mapping and constrain functions are used to gived mapping values and constrain the pins to those values so when in the loop function the have the mapped data to read from.

That code is doing no such thing. The value read from the 1st through 9th sensors are overwritten by mapping the last value read from sensor 10, to some range.

That mapped value is then overwritten by the last value read from the 10th sensor. The constrain is doing nothing, since SV will, by definition, be in the range 0 to 1023, and you are saying that the value must be in a larger range.

how do i control multiple outputs with multiple inputs using an array??

Well, the first thing that you need to do is to define what those multiple inputs are. Then, you need to define how you want to map those inputs to the multiple outputs. The use of arrays, at this time, is irrelevant.

What you are currently asking is for someone to please define f(x, y) = (a, b) for you. Only you can define how you want the “multiple inputs” to affect the “multiple outputs”.

i really need to finish this project soon

Perhaps it would help if you told us what “this project” is? It’s not homework, is it?

allot of what im doing is in no way irelvant im just going a different route. im an expierienced student in software engineering. thing is im just so unfamiliare with these microcontrollers and led’s lol.

anyway the project im helping a friend is pretty much the usual beer pong table. 20 rgb led’s controlled by 20 ir recievers that send signals based on the reflection of ir from an emiter.

first thing that happens is as follows.
i start a timer for everything to calibrate…
i use SV and SPT in replacement of the real values themselves.
in this manner i dont need individual calibration values for each sensor but rather one calibration value to map to each sensor so that they all have the same “0 line”(the point at which the reciever defines as the start point)
what happens next is i run a for loop/array(YES this is nececarry. reason being im storing the data from the REAL sensors and entering them into my log for use)
next the values them selves are mapped not acording to there own readings BUT to that of SV which took the value of a chosen sensor.

you see it doesnt matter AT ALL which sensor i choose to use for SV. the table is a level table and all sensorvalues should carry the same value anyway.

whats happening is this.
sensorvalue[i(the coresponding sensor pinand its value)] is mapped acording to a constant i.e SV and it mapped to the min and max (which were applied in calibration).

this is important because it keeps all sensors mapped in the same manner.

next i constrain the values of all sensors to that of once again SV to 0-1023.
this is once again because they should all carry the same exact calibration and act.

in laymens terms this is all thats happening.

i give an equal calibration to EVERY sensor.

now here is where the problems come in.
all i want is a system to connect and control all 20 led’ based on there sensor values
WITHOUT simply typing every single line
^ this is the point of arrays…

the thing is ur thinking about it wrong. SV isnt the 10th reading but rather a COPY of the tenth reading. i could make it a copy of the 3rd reading and get the same result. all SV is, is a refrence. every thing else is still individual.

and easy way to explain exactly what i want is this.

1.take/calibrate the sensors.
2.manipulate the led’s brightness based on the sensors reading.

honestly in the end result im simply going to have the leds iether ON or OFF. so any effect would do really.

_
what would help me the most is if someone could simply right out a quick script to show off controling multiple leds with coresponding sensors using arrays.

i want arrays solely for the reason that i dont want to have massive clutter and such.

any help is apriciated. thank you in advance.

ok here is an older code i found.
as a side note the code i’ve been posting isnt the code im using. its just the simple version i typed up that does the same thing. basicly if someone helped me with that they would inevitably help me with this problem.

but here can someone manipulate this so it works with multiple entintys instead of just 1. 20 would be perfect but any number over 1 will do fine. it would be PERFECT if you used an array for this.

this is old code i got from a friend and slightly edited. it was the ORIGINAL prototype.

// These constants won't change:
const int sensorPin = A0;    // pin that the sensor is attached to
const int ledPin = 9;        // pin that the LED is attached to

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value


void setup() {
  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds 
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }

  // signal the end of the calibration period
  digitalWrite(13, LOW);
}

void loop() {
  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
}

as i said before turning this into something multiple rather then singular would completely solve my problem. its something that i dont understand how the microcontroller takes in info and outputs. it would help so much. thank you. i apriciate what your doing

Wouldn’t it be as simple as:

int ledPin[] = { 1, 2, 3, 4, ... }; //list the pins of all the LEDs here
int sensorPin[] = { 1, 2, 3, 4, ... }; //list the pins of all the sensors here
int count = 20; //the number of sensors/LEDs you have

void loop() {
    for( int i = 0; i < count; i++ )
    {
        // read the sensor:
        sensorValue = analogRead(sensorPin[ i ]);

        // apply the calibration to the sensor reading
        sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

        // in case the sensor value is outside the range seen during calibration
        sensorValue = constrain(sensorValue, 0, 255);

        // fade the LED using the calibrated value:
        analogWrite(ledPin[ i ], sensorValue[ i ]);
    }
}

This still leaves you with the rather thorny issue of how you hook up 20 LEDs and 20 sensors to one Arduino (unless you have a Mega, I suppose).