Pages: [1] 2   Go Down
Author Topic: Blinking in different configurations  (Read 381 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Helo
I am just starting with the Arduino Leonardo.

I used found here code
Code:
/* 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 ?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34518
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a read of this to fully understand what you are doing
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html
Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/* 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;
  }
}
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7642
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This demo several things at a time may give you some ideas.

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, i will try to deal with it. Maybe i will put it on 3 chips than on 1.
« Last Edit: August 06, 2014, 04:03:56 am by nexusprime » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
 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);                            
}
}
}
« Last Edit: August 06, 2014, 10:30:42 am by nexusprime » Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7642
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 06, 2014, 10:32:22 am by nexusprime » Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7642
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* 10496912_686938821375656_7848806779336921028_o.jpg (31.33 KB, 1024x566 - viewed 11 times.)
« Last Edit: August 06, 2014, 02:36:51 pm by nexusprime » Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7642
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

a lot of leds.

Does that mean 10, 100 or 1000?

Does every one of them need a separate blinking pattern?

...R
Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 06, 2014, 11:40:51 pm by nexusprime » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4324
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7642
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: