8 LEDs, 1 pushbutton

How can I make into the program with these 4 patterns?

• Firework
• Directional light
• Shooting star
• Breathing Light

Probably not the start you wanted, but using pins 0/1 of an Arduino isn’t a good place for a beginner.

They’re shared with the serial port and USB programming port.

If you have the Arduino basics already understood, then move on to reading about and experimenting with arrays.

Also look at the state change detect example to see how to get the button to work correctly press by press.

(If you don't have the Arduino basics clear in your mind, you need to take care of that first of course.)

That involves dimming the lights up and down. You can only dim and LED that is attached to a a PWM capable pin. On a Uno there are only 6 of these and they are marked with a ~ in front of the pin number.

Also your switch is wired up wrong. It should be between the pin and ground, no resistor, and then when using the pin mode call in the setup function specift INPUT_PULLUP then a button press will read low and no press will read high.

It would be good if the state change detect example could be updated to work that way.

It would, but the so-called "tutorials" on the Arduino site are set in stone.

(Kidney stone! :grin:)

Hello
Publish a specification in detail how this illuminations effects shall looks like.
Have a nice day and enjoy coding in C++.

Hi, @anon61619149
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Can you please tell us your electronics, programming, arduino, hardware experience?

Have you written some code to prove the button works?
Have you written some code to prove the LEDs work?

Thanks... Tom... :grinning: :+1: :coffee: :australia:

This is the currently I have coded. I not very sure how to continue from this?

int pinsCount = 8; // declaring the integer variable pinsCount
int pins[x] = {0,1,2,3,4,5,6,7}; // declaring the array pins[x]

void setup() {
DDRD = 0xff;
DDRB = 0x00;
Serial.begin(57600);
for (int i=0; i<pinsCount; i=i+1){ // counting the variable i from 0 to 9
pinMode(pins[i], OUTPUT); // initialising the pin at index i of the array of pins as OUTPUT
}
}

void loop() {
for (int i=0; i<pinsCount; i=i+1){ // chasing right
digitalWrite(pins[i], HIGH); // switching the LED at index i on
delay(100); // stopping the program for 100 milliseconds
digitalWrite(pins[i], LOW); // switching the LED at index i off
}
for (int i=pinsCount-1; i>0; i=i-1){ // chasing left (except the outer leds)
digitalWrite(pins[i], HIGH); // switching the LED at index i on
delay(100); // stopping the program for 100 milliseconds
digitalWrite(pins[i], LOW); // switching the LED at index i off
}
}

digitalWrite(pins[i], HIGH);
delay(100);
digitalWrite(pins[i], LOW);
delay(100);

Hi, @anon61619149
To add code please click this link;

Here is your code with [ CTRL ] [ T ] auto formatted in the IDE.

int pinsCount = 8; // declaring the integer variable pinsCount
int pins = {0, 1, 2, 3, 4, 5, 6, 7}; // declaring the array pins

void setup()
{
  DDRD = 0xff;
  DDRB = 0x00;
  Serial.begin(57600);
  for (int i = 0; i < pinsCount; i = i + 1) // counting the variable i from 0 to 9
  {
    pinMode(pins[i], OUTPUT); // initialising the pin at index i of the array of pins as OUTPUT
  }
}

void loop()
{
  for (int i = 0; i < pinsCount; i = i + 1) // chasing right
  {
    digitalWrite(pins[i], HIGH); // switching the LED at index i on
    delay(100); // stopping the program for 100 milliseconds
    digitalWrite(pins[i], LOW); // switching the LED at index i off
  }
  for (int i = pinsCount - 1; i > 0; i = i - 1) // chasing left (except the outer leds)
  {
    digitalWrite(pins[i], HIGH); // switching the LED at index i on
    delay(100); // stopping the program for 100 milliseconds
    digitalWrite(pins[i], LOW); // switching the LED at index i off
  }
}

Tom.... :grinning: :+1: :coffee: :australia:

Hello
Post your sketch well formated, with comments and in so called code tags "</>" to see how we can help again.
Don´t forget to give feedback wrt other posts.
p.s. Tom was faster

Hi,
This;

int pins = {0, 1, 2, 3, 4, 5, 6, 7}; // declaring the array pins

Needs to be;

int pins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // declaring the array pins

Tom.... :grinning: :+1: :coffee: :australia:

I needed a pull-up resistor as well & the 4 patterns that I have mention which is Firework, Directional Light, Shooting star & Breathing Light. Which line of the code should I add in?

int pinsCount = 8;                       // declaring the integer variable pinsCount
int pins[] = {0, 1, 2, 3, 4, 5, 6, 7};   // declaring the array pins[]

void setup() {
  DDRD = 0xff;
  DDRB = 0x00;
  Serial.begin(57600);
  for (int i = 0; i < pinsCount; i = i + 1) // counting the variable i from 0 to 9
  {
    pinMode(pins[i], OUTPUT);            // initialising the pin at index i of the array of pins as OUTPUT
  }
}

void loop() {
  for (int i = 0; i < pinsCount; i = i + 1) { // chasing right
    digitalWrite(pins[i], HIGH);         // switching the LED at index i on
    delay(100);                          // stopping the program for 100 milliseconds
    digitalWrite(pins[i], LOW);      // switching the LED at index i off
    delay(100);              // stopping the program for 100 milliseconds
  }
  for (int i = pinsCount - 1; i > 0; i = i - 1) { // chasing left (except the outer leds)
    digitalWrite(pins[i], HIGH);         // switching the LED at index i on
    delay(100);                          // stopping the program for 100 milliseconds
    digitalWrite(pins[i], LOW);          // switching the LED at index i off
    delay(100);              // stopping the program for 100 milliseconds
  }
}

That's a question of taste. Without the latter delay, the next led turns on at the same time the previous one turns off. The latter delay is needed if it's a single led blinking, but here it's a row of leds with a chasing pattern.

Hello
To run differnet LED pattern a button-, a time-handler and a FSM is needed.
Have a nice day and enjoy coding in C++.

Hi, @anon61619149

Can I suggest you look at switch.. case function.
You can use the button to advance a counter, the value of the counter selecting the case which will have thecode for each particular pattern.

Tom... :grinning: :+1: :coffee: :australia:

There are some codes errors which I not sure where to fix can someone help me?
Please help me to modify the code better thank you. I need the patterns to be included inside the project it's due soon thank you.

int seconds = 0, count = 0, CountPat = 0;
char Brightness = 0, i = 0, FAT, SPEED;                            // declaring the integer variable pinsCount
char Pat0[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; //Pattern 1
char Pat1[] = {0x80, 0x40, 0x20, 0x80, 0x04, 0x02, 0x01, 0x00}; //Pattern 2
char Pat2[] = {0x80, 0x40, 0x20, 0x10, 0x04, 0x02, 0x01, 0x00}; //Pattern 3
char Pat3[] = {0x80, 0x40, 0x20, 0x10, 0x04, 0x02, 0x01, 0x00}; //Pattern 4

void setup() {
  DDRD = 0xFF;             //Declare PORTD as Output for all 8 LEDs
  DDRB = 0xE0;
  TCCR2A = 0x02;
  TCCR2B = 0x04;
  OCR2A = 250 - 1;
  TIMSK2 = 0x02;             //It cause the program to interrupt
}

void Bright_CTRL (void) {
  if ((PINB & 0x10) == 0x10)
  {
    while ((Brightness >= 1) && (Brightness <= 1) PORTD = 8;
  }
}

void shiftPat1 (void) {
  PORTD = Pat0[i];
  Bright_CTRL();
}

void shiftPat2 (void) {
  PORTD = Pat1[i];
  Bright_CTRL();
}

void shiftPat3 (void) {
  PORTD = Pat2[i];
  Bright_CTRL();
}

void shiftPat4 (void) {
  PORTD = Pat3[i];
  Bright_CTRL();
}

ISR (TIMER2_COMPA_vect)
count++;
CountPat++;
if (CountPat >= (SPEED + 1) * 100)
{
  CountPat = 0;
  i++;
  if (i > 7) i = 0;
}
Brightness++;
else if (Brightness > 9) Brightness = 0;
seconds++;
count = 0;
}


void loop(void) {
  SPEED = PINB & 0x03;
  PAT = (PINB >> 2) & 0x03;
  if (PAT == 0) shiftPat1;
  else if (PAT == 1) shiftPat2;
  else if (PAT == 2) shiftPat3;
  else if (PAT == 3) shiftPat4;
}

Hello
Do you have to use DDRx commands ?

Yes, I need to.