hello
well want multi tasking arduino.
i want blink diodes example led on pin 13 500mson 350msoff 480mson 880msoff
i have code here
class flasher
{
// class member variables
// these initialized @ startup
int ledpin; // number of led pin
long ontime; // milliseconds of on-time
long offtime; // milliseconds of off-time
// these maintain current state
int ledstate; // ledstate used set led
unsigned long previousmillis; // store last time led updated
// constructor - creates flasher
// , initializes member variables , state
public:
flasher(int pin, long on, long off)
{
ledpin = pin;
pinmode(ledpin, output);
ontime = on;
offtime = off;
ledstate = low;
previousmillis = 0;
}
void update()
{
// check see if it's time change state of led
unsigned long currentmillis = millis();
if((ledstate == high) && (currentmillis - previousmillis >= ontime))
{
ledstate = low; // turn off
previousmillis = currentmillis; // remember time
digitalwrite(ledpin, ledstate); // update actual led
}
else if ((ledstate == low) && (currentmillis - previousmillis >= offtime))
{
ledstate = high; // turn on
previousmillis = currentmillis; // remember time
digitalwrite(ledpin, ledstate); // update actual led
}
}
};
flasher led1(12, 100, 400);
flasher led2(13, 350, 350);
void setup()
{
}
void loop()
{
led1.update();
led2.update();
}
it works ok on , off time,
i need professional me bit on off on off on off different timing settings.
regards
milan
well want multi tasking arduino.
i want blink diodes example led on pin 13 500mson 350msoff 480mson 880msoff
i have code here
class flasher
{
// class member variables
// these initialized @ startup
int ledpin; // number of led pin
long ontime; // milliseconds of on-time
long offtime; // milliseconds of off-time
// these maintain current state
int ledstate; // ledstate used set led
unsigned long previousmillis; // store last time led updated
// constructor - creates flasher
// , initializes member variables , state
public:
flasher(int pin, long on, long off)
{
ledpin = pin;
pinmode(ledpin, output);
ontime = on;
offtime = off;
ledstate = low;
previousmillis = 0;
}
void update()
{
// check see if it's time change state of led
unsigned long currentmillis = millis();
if((ledstate == high) && (currentmillis - previousmillis >= ontime))
{
ledstate = low; // turn off
previousmillis = currentmillis; // remember time
digitalwrite(ledpin, ledstate); // update actual led
}
else if ((ledstate == low) && (currentmillis - previousmillis >= offtime))
{
ledstate = high; // turn on
previousmillis = currentmillis; // remember time
digitalwrite(ledpin, ledstate); // update actual led
}
}
};
flasher led1(12, 100, 400);
flasher led2(13, 350, 350);
void setup()
{
}
void loop()
{
led1.update();
led2.update();
}
it works ok on , off time,
i need professional me bit on off on off on off different timing settings.
regards
milan
if want use program written, see multiblink sketch in library site (link below). blink patterns defined in data table , used program whatever need timing, on/off , fade in/out.
Arduino Forum > Using Arduino > LEDs and Multiplexing > Led blinking, simple?
arduino
Comments
Post a Comment