Go Down

Topic: Blinking in different configurations (Read 467 times) previous topic - next topic

nexusprime

Helo
I am just starting with the Arduino Leonardo.

I used found here code
Code: [Select]

/* Blink Multiple LEDs without Delay
*
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function.  This means that other code
* can run at the same time without being interrupted by the LED code.
*/
int POST = 13;                // LED connected to digital pin 13
int KIER = 12;
int STOP = 11;
int value1 = LOW;                // previous value of the LED
int value2 = LOW;
int value3 = LOW;// previous value of the LED
long time1  = millis();
long time2 = millis();
long time3 = millis();

long czasPOST = 1000;           // interval at which to blink (milliseconds)
long czasKIER = 500;
long czasSTOP = 300;

void setup()
{
  pinMode(POST, OUTPUT);      // sets the digital pin as output
  pinMode(KIER, OUTPUT);
  pinMode(STOP, OUTPUT);
}

void loop()
{
  unsigned long m = millis();

  if (m - time1 > czasPOST){
    time1 = m;

    if (value1 == LOW)
      value1 = HIGH;
    else
      value1 = LOW;

    digitalWrite(POST, value1);
  }

  if (m - time2 > czasKIER){
    time2 = m;

    if (value2 == LOW)
      value2 = HIGH;
    else
      value2 = LOW;

    digitalWrite(KIER, value2);
  }
  if (m - time3 > czasSTOP){
    time3 = m;
   
    if (value3 ==LOW)
      value3 = HIGH;
      else
      value3 = LOW;
     
      digitalWrite(STOP, value3);
  }
}


and this is going very well, but what to do to...
make for example the POST after 20 repeats  light on with no blinking for 1 minute and then again make it blinking for some time or cycle ?
How to make such command? I want to make a testing program for my device and put it on the Attiny85. I saw here that it support 3 outputs.
and another thing...How to make the led more time HIGH than LOW in the blinking script ?

Grumpy_Mike


BulldogLowell

think about creating a function for each led.  You can call the function as many times as you want

Quote
and another thing...How to make the led more time HIGH than LOW in the blinking script ?


I included an example below:

Code: [Select]
/* Blink Multiple LEDs without Delay
*
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function.  This means that other code
* can run at the same time without being interrupted by the LED code.
*/
int POST = 13;                // LED connected to digital pin 13
int KIER = 12;
int STOP = 11;
int value1 = LOW;                // previous value of the LED
int value2 = LOW;
int value3 = LOW;// previous value of the LED
long time1  = millis();
long time2 = millis();
long time3 = millis();

long czasPOST = 1000;           // interval at which to blink (milliseconds)
long czasKIER = 500;
long czasSTOP = 300;
unsigned long startTime3;
unsigned long onTime = 1900UL;
unsigned long interval = 2000UL;// this combination turns led off for 100ms of a 2 sec total time

void setup()
{
  pinMode(POST, OUTPUT);      // sets the digital pin as output
  pinMode(KIER, OUTPUT);
  pinMode(STOP, OUTPUT);
}

void loop()
{
  unsigned long m = millis();
  if (m - time1 > czasPOST)
  {
    time1 = m;
    if (value1 == LOW)
      value1 = HIGH;
    else
      value1 = LOW;
    digitalWrite(POST, value1);
  }
  if (m - time2 > czasKIER)
  {
    time2 = m;
    if (value2 == LOW)
      value2 = HIGH;
    else
      value2 = LOW;
    digitalWrite(KIER, value2);
  }
  blink3(); //your new function
}

void blink3()
{
  unsigned long elapsedTime = millis() - startTime3;
  if (elapsedTime < onTime) //on time
  {
    digitalWrite(STOP,HIGH);
  }
  else if (elapsedTime < interval) //total time
  {
    digitalWrite(STOP,LOW);
  }
  else
  {
    startTime3 += interval;
  }
}

Robin2


nexusprime

#4
Aug 06, 2014, 10:56 am Last Edit: Aug 06, 2014, 11:03 am by nexusprime Reason: 1
ok, i will try to deal with it. Maybe i will put it on 3 chips than on 1.

nexusprime

#5
Aug 06, 2014, 05:07 pm Last Edit: Aug 06, 2014, 05:30 pm by nexusprime Reason: 1
another question...
I want to make a fade on 3 Attiny pins. The pin 4 is OK but the 0 and 1 is little jerky, it is not a soft fading. How to deal with this and make it soft? i used standard fading code. i know this is all about the PWM

Code: [Select]
/*
Fade

This example shows how to fade an LED on pin 9
using the analogWrite() function.

This example code is in the public domain.
*/
int led = 0;
int led2 = 1;
int led3 = 4;
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  {
 // declare pin 9 to be an output:
 pinMode(led, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop()  {
 // set the brightness of pin 9:
 analogWrite(led, brightness);    

 // change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;

 // reverse the direction of the fading at the ends of the fade:
 if (brightness == 0 || brightness == 255) {
   fadeAmount = -fadeAmount ;
 }    
 // wait for 30 milliseconds to see the dimming effect    
 delay(5);                            
{

 // set the brightness of pin 9:
 analogWrite(led2, brightness);    

 // change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;

 // reverse the direction of the fading at the ends of the fade:
 if (brightness == 0 || brightness == 255) {
   fadeAmount = -fadeAmount ;
 }    
 // wait for 30 milliseconds to see the dimming effect    
 delay(5);                            
{

 // set the brightness of pin 9:
 analogWrite(led3, brightness);    

 // change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;

 // reverse the direction of the fading at the ends of the fade:
 if (brightness == 0 || brightness == 255) {
   fadeAmount = -fadeAmount ;
 }    
 // wait for 30 milliseconds to see the dimming effect    
 delay(5);                            
}
}
}

Robin2


Maybe i will put it on 3 chips than on 1.


I hope you are not thinking of 3 separate Arduinos to do something that is more easily done with one.

...R

nexusprime

#7
Aug 06, 2014, 05:28 pm Last Edit: Aug 06, 2014, 05:32 pm by nexusprime Reason: 1
I mine use one attina to control HIGH LOW on pins which will be connected to the VCC of 3 Attinas with different program each.  I can use blinking program to turn on and off VCC. I think this is the easiest way.

Robin2


I mine use one attina to control HIGH LOW on pins which will be connected to the VCC of 3 Attinas with different program each.  I can use blinking program to turn on and off VCC. I think this is the easiest way.


How many LEDs do you want to blink? The code in several things at a time could be easily extended to do several.

...R

nexusprime

#9
Aug 06, 2014, 09:35 pm Last Edit: Aug 06, 2014, 09:36 pm by nexusprime Reason: 1
a lot of leds. 3 line about 12V/350mA each.
Here is schematic for Attiny.

Left side of schematic represent the Attiny because i dont have the chips in iCircuit app

Robin2


a lot of leds.


Does that mean 10, 100 or 1000?

Does every one of them need a separate blinking pattern?

...R

BulldogLowell


a lot of leds. 3 line about 12V/350mA each.
Here is schematic for Attiny.

Left side of schematic represent the Attiny because i dont have the chips in iCircuit app


attach a shift register and go nuts

nexusprime

#12
Aug 07, 2014, 06:24 am Last Edit: Aug 07, 2014, 06:40 am by nexusprime Reason: 1
I will be more specific.
I have 3 lines of leds. Each have about 11 leds. Each line require about 350mA and 12v.
Now...
I need 3 different programs for drive all leds in the same time.
First is slow blinking
Seccond is fast blinking
Third is soft fading

I am planing to put 3 programs on 3 chips which will be connected to the resistors and first transistors the pnp transistors in the schematic.
More specific...

I will use 3 attiny pins which will be connected to the transistors, each pin each transistor.

So in ready to go device 9 pin of 3 attines will be connected to the 3 transistors.

This 3 chips will be drived by another 4 chip which will be give them command to start doing thing.

the 4 chip will be connected to the voltage devider.

Yes, i could put the shift register, but using the arduino i can make different times of doing things for each of 3 chips.

This is the whole idea.

UKHeliBob

Quote
Yes, i could put the shift register, but using the arduino i can make different times of doing things for each of 3 chips.
As has been pointed out, you can turn 3 sets of LEDs on and off at different rates, including a slow fade,  using just one Arduino, so why use 4 of them ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Robin2


I need 3 different programs for drive all leds in the same time.
First is slow blinking
Seccond is fast blinking
Third is soft fading


That's more or less what I thought. The several things at a time demo pretty much does that out of the box.

...R

Go Up