SOS with variables

in the previous code we have an SOS with simple instructions. We are going to covert simple nstructions in to instructions with variables. Variables are declared (defined) at the begining of the code. Remember that are many types of variables(int, byte, float, bool, double, char...), does variables can be signed or unsigned variables, global variables are used all along the code, and ocal variables are used only inside a function and do not exst outside that specific function. In this case the global vrialble is t=200. Sometimes a variable can be constant in all the code so i can declare const int t=200;. When i declare a variable, the computer keep a space in the memory for that vriable and keep that name.

what is the advantage of creating variables?

you don't need to repeat all the time the same value. it is more effective because i write once and the value changes many times. Time variable is sometimes t and somtimes 3*t because the rules of the Morse code:

another posibility is to create 3 variables, one is dot, another is dash and the last is space, the code will be: const int dot=200; cost int dash= dot*3; const int space= dot*7;

the structure of the code is always the same:

  1. comment about the objective and author of the code
  2. importing libreries need for my code, for exemple il i using computer vision i need to import the computer vison llibrary in the order to use the computer vision instruction.
  3. setup function contains de settings of my code: output/ input, screem size...
  4. my own functions created by myself to be used in the main code
  5. the name code is the loop function, and in this case contain only simple instructions with variables and do not call any function created by mysef
  6. 
        void setup() {
      // initialize digital pin LED_BUILTIN as an output.
      pinMode(LED_BUILTIN, OUTPUT);
    }
    
    // the loop function runs over and over again forever
    void loop() {
    
      const int t =200;
      
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);                       // wait for a second
    
       digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);        
    
       digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);        
    
        delay(3*t);        
    
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(3*t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);                       // wait for a second
    
       digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(3*t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);        
    
       digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(3*t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(3*t); 
    
          delay(3*t);        
    
     digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);                       // wait for a second
    
       digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);        
    
       digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(t);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(t);        
    
        delay(7*t); 
    }