hi new member and im just starting to learn about the arduino’s capability’s.
I was looking at the blinking light tutorial and thought I ought to make something like it but a little more complex.
/*
By: Z3R0 C001
Date: Sunday, Dec, 13, 2009
Discription: A morse code SOS program using while statements.
*/
int ledpin = 13; //LED CONNECTED TO PIN 13
int count = 0; // first interger to count slow blinks
int selo = 0; //second int to count fast blinks
void setup() {
//makes the pin13 the output
pinMode(ledpin, OUTPUT);
}
void loop()
{
label:
while (count < 1) /* this while loop makes the pause between the last quick flash to the first long flash the same length as the rest of the pauses between the other long flashes */
{
delay(300);
digitalWrite(ledpin, HIGH); //turns led pin on
delay(900);
digitalWrite(ledpin, LOW);
delay(500);
++count;
}
while (count >= 1 && count < 3) // second and third long flash
{
++count;
digitalWrite(ledpin, HIGH); //turns led pin on
delay(900);
digitalWrite(ledpin, LOW);
delay(500);
}
while (count = 3 && selo < 3) // short flashes
{
++selo;
digitalWrite(ledpin, HIGH); //turns led pin on
delay(200);
digitalWrite(ledpin, LOW);
delay(200);
}
count = 0; //resetting the variables
selo = 0;
goto label; //starts the while loops over
}
now i was trying to make this simpler and much smaller but i gave up after a bit
i was wondering if there was a cleaner shorter way.
The use of subroutines/functions to group related commands/behavior is the cleanest way to write code. It is not necessarily the shortest, but short code tends to be obscure code, and obscure code tends to be hard to maintain. Lots of head-scratching, wondering "why did I (they) do that?".