Hello AAC forum,
Have done the Blink Without Delay in the Examples. Have
also done a sketch that blinks several LEDs by having each LED
have its own LEDx BWOD function and calling the different LEDx
functions from the loop() function. (Can post this sketch if
you are interested but basically it creates a BWOD function for
each LED and then calls each LED BWOD function from the loop() function.
Several forum posts on controlling several LEDs with different
intervals have also been studied, copied and implemented
successfully.
In these examples the BWOD toggles between high and low using the constuct
What is sought is to have the same LED blink longer
off than on. So it was conjectured that the toggle constuct
copied herewith above would be omitted and there should
be two BWOD functions, on for ON and another
for OFF.
Copied my attempt at this herewith below. Having trouble
getting it to compile.
Compilation error: expected unqualified-id before 'if'
Thanks.
Allen Pitts
Dallas TX
Have done the Blink Without Delay in the Examples. Have
also done a sketch that blinks several LEDs by having each LED
have its own LEDx BWOD function and calling the different LEDx
functions from the loop() function. (Can post this sketch if
you are interested but basically it creates a BWOD function for
each LED and then calls each LED BWOD function from the loop() function.
Several forum posts on controlling several LEDs with different
intervals have also been studied, copied and implemented
successfully.
In these examples the BWOD toggles between high and low using the constuct
C++:
if the LED is off turn it on and vice-versa:
if (ledStateOn == LOW) {
ledStateOn = HIGH;
} else {
ledStateOn = LOW;
}
off than on. So it was conjectured that the toggle constuct
copied herewith above would be omitted and there should
be two BWOD functions, on for ON and another
for OFF.
Copied my attempt at this herewith below. Having trouble
getting it to compile.
Compilation error: expected unqualified-id before 'if'
Thanks.
Allen Pitts
Dallas TX
C++:
/* Blink without Delay
based on documentation found at
https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay/
and
Blink_1_wo_Delay_Attiny85_240402,ino
Blink_1_wo_Delay_Attiny85_two_intervals_2400615.ino (this sketch)
uses two intervals so the On interval can be different from the Off interval.
*/
// constants won't change. Used here to set a pin number :
const int ledPin3 = 3; // the number of the LED pin
// Variables will change :
int ledStateOn = LOW;
int ledStateOff = LOW;
unsigned long previousMillisOn = 0;
unsigned long previousMillisOff = 0;
// constants won't change :
const long intervalOn = 1000;
const long intervalOff = 500;
void setup() {
// set the digital pin as output:
pinMode(ledPin3, OUTPUT);
}
void loop() {
runLED3();
}
void runLED3() {
unsigned long currentMillisOn = millis();
if (currentMillisOn - previousMillisOn >= intervalOn && ledStateOn = LOW)
{
// save the last time you blinked the LED
previousMillisOn = currentMillisOn;
// if the LED is off turn it on and vice-versa:
//if (ledStateOn == LOW) {
// ledStateOn = HIGH;
//} else {
// ledStateOn = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin3, ledStateOn);
}
unsigned long currentMillisOff = millis();
if (currentMillisOff - previousMillisff >= intervalOff && ledStateOff = HIGH)
{
// save the last time you blinked the LED
previousMillisOff = currentMillisOff;
// if the LED is off turn it on and vice-versa:
//if (ledStateOn == LOW) {
// ledStateOn = HIGH;
//} else {
// ledStateOn = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin3, ledStateOff);
ledStateOn = LOW;
}
}
Attachments
-
1.8 KB Views: 1