hallo
i purchased an arduino just a few days ago and i am a total newbie to programming and electrical circuitry.
although i am of course eager to learn.
what i want to do:
i got 4 leds and 4 pressure-sensors connected and they work (means i get ok data) (only 4 instead of 6 leds connected since i only have 4 sensors yet).
i want to use flex-sensors later but have to buy them yet.
for each led i want one sensor. when the sensor gets some input (a person or maybe the wind touches it the led should fade up and down again.
(for the beginning a programmed fade is ok. maybe some other time: depending on how much bending the higher the led schould shine).
i managed to program a fade and to trigger it.
problem:
the fade should take about 2 or 3 seconds. while on led is fading non of the other leds/sensors respond.
a far as i understand a computer(arduino) is only able to perform on task(the fading process) at once.
so
how can i manage to trigger leds while others are still fading?
i post here 'cause i dont know exacly where to look for help in the tutorials.
i also understand that since the arduino only has 6 analog inputs there is a multiplexer (which i have) to increase the number of analog inputs and (i guess with another multiplexer) outputs. so i dont have to buy three or for arduinos to trigger lets say 25 leds/sensors.
hope this is not too much talk but i think the problem is easy to solve if you know how.
unfortunatly i cannot post the code i wrote so far cause this aint my pc.
but maybe there are links with pre-written code that i could use.
a far as i understand a computer(arduino) is only able to perform on task(the fading process) at once.
Almost correct. Just about any processor can do only one thing at a time.
However, by doing things fast enough, it is possible to give the impression of doing many things at a time.
This has been the cornerstone of multi-user computing since at least the 1960s.
i managed to program a fade and to trigger it.
problem:
the fade should take about 2 or 3 seconds. while on led is fading non of the other leds/sensors respond.
Have a look at the the "blink-without-delay" example in the tutorial, and try to understand all the other things your processor could be doing.
It says to the AVR "do nothing for 30 milliseconds".
Doesn't sound very long, does it? There are 33.33 such periods each second.
This is a processor running at 16 MHz, so using as a rule-of-thumb of one instruction per clock cycle, that's 480 000 instructions spent doing nothing. Even if it were one instruction per four clock cycle, that's a lot of wasted time.
hi there
done some programming and came up with a solution that works perfectly (hope that i done allright with the array).
heres the code (in which i only use to leds and two sensors, but with array i guess that up to six is no prob)
also i dont have the flex sensors yet. so i work with pressure sensors, which wont make a big difference in this case.
const int ledPin[2] = { 10,11};
const int senPin[2] = { 0,1};
int analogValue[2] = {0,0};
int counter[2] = {0,0};
void setup() {
Serial.begin(9600);
for (int i = 0; i < 1; i++) {
pinMode(ledPin[i], OUTPUT);
pinMode(senPin[i], INPUT);
}
}
void loop() {
for (int i = 0; i < 2; i++) {
analogValue[i] = analogRead(senPin[i]);
Serial.println(analogValue[i]);
if (analogValue[i] >=150) {
analogValue[i] = analogValue[i] / 4;
digitalWrite(ledPin[i], analogValue[i]);
counter[i] = analogValue[i];
}
else {
if (counter[i] > 0) {
counter[i] = counter[i] - 1;
}
else {
counter[i] = 0;
}
analogWrite(ledPin[i], counter[i]);
}
}
delay(20);
}
the code seems to work for two leds.
please comment.
i havent used the millis() function cause couldnt come up with a solution which uses that function...
so as you can guess, 6 leds are not enough.
i read something about a multiplexer. only overflew the tutorial for that though.
i will post after the read which will definitly lead to some questions.