Simon Monk SOS example Programming Arduino Book timing error question
i have been re-writing monk's examples learn arduino syntax. when uploaded 1 sketch_05_02 did not give smooth sos in morse. added 200msec pause @ beginning of execution of flash (int duration) function. works, can't figure out why. in understaning flow of sketch appreciated.
this his.
here mine. added delay(duration) , spaced delay between loop bit longer make easier evaluate result.
this his.
code: [select]
// sketch 05-02
int ledpin = 13;
int durations[] = {200, 200, 200, 500, 500, 500, 200, 200, 200};
void setup()
{
pinmode(ledpin, output);
}
void loop()
{
(int = 0; < 9; i++)
{
flash(durations[i]);
}
delay(1000);
}
void flash(int duration)
{
digitalwrite(ledpin, high);
delay(duration);
digitalwrite(ledpin, low);
delay(duration);
}
here mine. added delay(duration) , spaced delay between loop bit longer make easier evaluate result.
code: [select]
//this sketch uses array flash sos
//simon sketch has problems - timing off - needs 200msec delay @ beginning of last block
//i found trial , error don't know why
int ledpin = 13;
int durations[] = {200, 200, 200, 500, 500, 500, 200, 200, 200};
void setup()
{
pinmode(ledpin, output);
}
void loop()
{
(int = 0; < 9; i++)
{
flash(durations[i]); //create function point positions 0-9 in durations array data
}
delay(2000);
}
void flash(int duration) //call flash function , give data in durations array local variable named duration
{
delay(duration);
digitalwrite(ledpin, high);
delay(duration);
digitalwrite(ledpin, low);
delay(duration);
}
according wikipedia article on morse code:
a 'dash' should 3 times length of 'dot'.
the time between dots or dashes in letter should same time dot.
the time between letters should 3 dot times.
i suspect changes got closer standard still off. try version:
a 'dash' should 3 times length of 'dot'.
the time between dots or dashes in letter should same time dot.
the time between letters should 3 dot times.
i suspect changes got closer standard still off. try version:
code: [select]
int ledpin = 13;
const int dot = 150;
const int dash = dot * 3;
int durations[] = {dot, dot, dot, dash, dash, dash, dot, dot, dot};
void setup() {
pinmode(ledpin, output);
}
void loop() {
(int = 0; < 9; i++) {
flash(durations[i]);
if (i == 2 || == 5)
delay(dash - dot); // inter-letter additional time
}
delay(1000);
}
void flash(int duration) {
digitalwrite(ledpin, high);
delay(duration);
digitalwrite(ledpin, low);
delay(dot);
}
Arduino Forum > Using Arduino > Programming Questions > Simon Monk SOS example Programming Arduino Book timing error question
arduino
Comments
Post a Comment