Nuances of shetch Code
i have sample piece of code built 1 of embedded sketches
yes simple code , new @ arduino programming have coded in other languages c before , far can tell should working have tried different iterations different forms of if condition no success
here sketch , want flash between line 13 onboard led , external led on line 7 switch occur faster , faster until delay 0 starts slowing down until delay hits 1000 , loops again continuously
/*
blink
turns on led on 1 second, off 1 second, repeatedly.
this example code in public domain.
*/
// pin 13 has led connected on arduino boards.
// give name:
int led = 7;
int obled = 13;
int dlay = 100;
int val = 1;
// setup routine runs once when press reset:
void setup() {
// initialize digital pin output.
pinmode(led, output);
pinmode(obled, output);
}
// loop routine runs on , on again forever:
void loop() {
digitalwrite(led, high); // turn led on (high voltage level)
delay(dlay); // wait time
digitalwrite(led, low); // turn led off making voltage low
digitalwrite(obled, high); // turn obled on (high voltage level)
delay(dlay); // wait time
digitalwrite(obled, low); // turn obled off making voltage low
if ((dlay <= 0) || (dlay >=1000)) {
val= val * -1;
}
dlay = dlay + (val * 100);
}
it seems simple enough , should want cycles fast slow never goes fast again how stuck on high end of delay value. there nuance of sketch code missing.
yes simple code , new @ arduino programming have coded in other languages c before , far can tell should working have tried different iterations different forms of if condition no success
here sketch , want flash between line 13 onboard led , external led on line 7 switch occur faster , faster until delay 0 starts slowing down until delay hits 1000 , loops again continuously
/*
blink
turns on led on 1 second, off 1 second, repeatedly.
this example code in public domain.
*/
// pin 13 has led connected on arduino boards.
// give name:
int led = 7;
int obled = 13;
int dlay = 100;
int val = 1;
// setup routine runs once when press reset:
void setup() {
// initialize digital pin output.
pinmode(led, output);
pinmode(obled, output);
}
// loop routine runs on , on again forever:
void loop() {
digitalwrite(led, high); // turn led on (high voltage level)
delay(dlay); // wait time
digitalwrite(led, low); // turn led off making voltage low
digitalwrite(obled, high); // turn obled on (high voltage level)
delay(dlay); // wait time
digitalwrite(obled, low); // turn obled off making voltage low
if ((dlay <= 0) || (dlay >=1000)) {
val= val * -1;
}
dlay = dlay + (val * 100);
}
it seems simple enough , should want cycles fast slow never goes fast again how stuck on high end of delay value. there nuance of sketch code missing.
ok seems working fine nuance
Arduino Forum > Using Arduino > Programming Questions > Nuances of shetch Code
arduino
Comments
Post a Comment