hello guys, im new to arduino and i have been trying to do a single line of 6 Leds each with increasing Brightness(certain brightness) then move the brightest led (which is the last led of the 6) to cycle among the array
pinArray[] = {3, 5, 6, 9, 10, 11};
^ ^ ^ ^ ^ ^
the brightness of element 5 move to element0 and the element0 was suppose to move to element 1
anyone can kindly help me ? =)
sorry for my poor english
byte pinArray[] = {3, 5, 6, 9, 10, 11};
byte brightnessArray[]= {0,50,100,150, 200,255;};
byte x;
void setup(){
for (x=0; x<6; x=x+1){
pinMode (pinsArray[x], OUTPUT);
analogWrite (pinsArray[x], 0); // outputs off to start, assuming High out = LED on.
}
void loop(){
// time to update the brightnesses? Or however you determine that.
for (x=0; x<6; x=x+1){
analogWrite (pinArray[x], brightnessArray[x]);
}
// adjust brightnessArray for next time change
...
}
hey mike, i have tried crossroads code already as i mention above but his code doesn't complete my requirement. i still need the brightest led to move among those leds
brightnessLevel0, brightnessLevel1, brightnessLevel2, brightnessLevel3, brightnessLevel4, brightnessLevel5
then i need to
brightnessLevel5, brightnessLevel0, brightnessLevel1, brightnessLevel2, brightnessLevel3, brightnessLevel4
brightnessLevel4, brightnessLevel5, brightnessLevel3, brightnessLevel2, brightnessLevel1, brightnessLevel0
tony9349258:
hey mike, i have tried crossroads code already as i mention above but his code doesn't complete my requirement. i still need the brightest led to move among those leds
brightnessLevel0, brightnessLevel1, brightnessLevel2, brightnessLevel3, brightnessLevel4, brightnessLevel5
then i need to
brightnessLevel5, brightnessLevel0, brightnessLevel1, brightnessLevel2, brightnessLevel3, brightnessLevel4
brightnessLevel4, brightnessLevel5, brightnessLevel3, brightnessLevel2, brightnessLevel1, brightnessLevel0
im sorry if im confusing u guys
something like this perhaps?
const byte pinArray[6] = {3, 5, 6, 9, 10, 11};
byte brightnessArray[10]= { 0, 50, 100, 150, 200, 255, 200, 150, 100, 50};
void setup()
{
Serial.begin(115200);
for (int i = 0; i < 6; i++)
{
pinMode(pinArray[i], OUTPUT);// not necessary using analogWrite
analogWrite (pinArray[i], 0);
}
}
void loop()
{
//update the array
Serial.println(brightnessArray[0]);
for (int i = 0; i < 6; i++)
{
analogWrite(pinArray[i], brightnessArray[i]);
}
shiftMyArray();
delay(150);
}
void shiftMyArray()
{
byte byteBucket = brightnessArray[0];
for (int i = 0; i < 9; i++)
{
brightnessArray[i] = brightnessArray[i + 1];
}
brightnessArray[9] = byteBucket;
}
hey mike, i have tried crossroads code already as i mention above but his code doesn't complete my requirement.
Yes, he left you a bit of a blank to see if you could work it out. He told you what you needed when he said:-
// adjust brightnessArray for next time change
...
So what BulldogLowell showed you was a way of adjusting the values in that array by shifting them one place to the left. He did this using a loop and made sure the original last value ended up round to the very right hand value of the array.
That is a very efficient way of doing it but maybe not one you would come up with yourself. So for extra marks how would you do it there are a few ways, also how would you make it move the other way?
Note the brightness moves round and round, as the bright one falls of the end it appears on the other side.
How can you make it bounce backwards and forwards?
Finally what about having a brightness array that is much longer than the actual number of LEDs you have? What effects could you generate with this.
These are the sorts of things you can play with to learn about coding.
hey, sorry for the late reply
thank you so much guys the code work perfectly
to move the other way is just by changing to
void shiftMyArray()
{
byte byteBucket = brightnessArray[9];//can u help me with this line and
for (int i = 9; i >=0 ; i--)
{
brightnessArray[i] = brightnessArray[i - 1];
}
brightnessArray[0] = byteBucket;//this line here, how do the two relate ?
}
i cant seem to make it work re bounce
const byte pinArray[] = {3, 5, 6, 9, 10, 11};
byte brightnessArray[]= { 0, 50, 100, 150, 200, 255, 200, 150, 100, 50};
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 6; i++)
{
pinMode(pinArray[i], OUTPUT);// not necessary using analogWrite
analogWrite (pinArray[i], 0);
}
}
void loop()
{
//update the array
Serial.println(brightnessArray[0]);
for (int i = 0; i < 6; i++)
{
analogWrite(pinArray[i], brightnessArray[i]);
}
shiftMyArrayRebounce();
shiftMyArray();
}
void shiftMyArrayRebounce()
{
byte byteRebounce = brightnessArray[9];
for (int i = 9; i >=0; i--)
{
brightnessArray[i] = brightnessArray[i-1];
}
brightnessArray[0] = byteRebounce;
delay(150);
}
void shiftMyArray()
{
byte byteBucket = brightnessArray[0];
for (int i = 0; i < 9; i++)
{
brightnessArray[i] = brightnessArray[i + 1];
}
brightnessArray[9] = byteBucket;
}
Read your code.
In the loop function you set the LEDs to the required brightness. Then you shift the brightness in one direction and then shift it in the other direction.
Result is it is in exactly the same state as before.
One way round it is to have a variable that indicates if you are shifting left or right and use that in an if statement to decide which of the two shifting functions to call.
No you need help with incrementing your pos variable. You only do that once per display of the LEDs.
Why have you stopped using functions for your shift left and right? Using functions breaks up the code and makes it much more easy for us humans to understand.