Abril's Website

Morse with arrays


int durations []= {200,200,200,600,600,600,200,200,200}; 
/* This array has elements in it, but I can create an empty array writing: int durations []; this makes a space in the PC's memory named durations that will only
accept sensers or integer (int) values i that will be made up of more than one value, specially an array or set of values. Sometimes it's interesting to create a
vacuum to then fill it for example with the values of a sensor, of one local json  (hosted on its server)*/
/* int creates the type of variable, durations is the variable name and [8] is array that is a set or list. The first element in array is 
0 index. This line helps the computer to have a pointer to an address of memory*/

void setup (){
  Seial.begin(9600); // speed of communication betwen the PC or console and the microcontroller
  for(int i=0, i< 9, i++){ // for is a loop that moves in an array
    Seial.println(durations[i]); 
    /* print means print continously and println means time by line, we write it in the console if in javascript we had written console.log, we write in Arduino
    Serial.print if we want to write variables in a continuous line or Serial.printIn if we want it to write the variables one by one (one variable per line); In
    means line and printIn prints line per line. Serial.print n affects Arduino, affects the console of the PC of the software Arduino. Serves for watching how are
    the variables working, hemm can tell you per example that a variables is undefined or null, or hemm can give you a correct value, per example for the humidity
    sensor to define a point to tell it if it has to deny it or not, if we put Serial.printIn(sensorValue). In this case Serial.printIn(durations[i]); will give the
    console a set of variables named array, specifically the name of this array is durations, that will give me from the value 0 to the 8, because we did a bucle for*/
    /* bucle for is very important at coding because tt saves us writing many times the same code, in this case:
    Seial.println(durations[0]); 
    Seial.println(durations[1]); 
    Seial.println(durations[2]); 
    Seial.println(durations[3]); 
    Seial.println(durations[4]); 
    Seial.println(durations[5]); 
    Seial.println(durations[6]); 
    Seial.println(durations[7]); 
    Seial.println(durations[8]);
   
    This is equivalent to:
    
     for(int i=0, i< 9, i++){ 
    Seial.println(durations[i]); } */
    
  }
  delay(1400);
  }
  void loop(){}

const int ledPin= 13;
int durations []= {200,200,200,600,600,600,200,200,200};

void setup(){
  pinMode(ledPin, OUTPUT);
}
void flash(int delayPeriod){ // parameter or argument
  digitalWrite(ledPin, HIGH);
  delay(delayPeriod);
  digitalWrite(ledPin, LOW);
  delay(delayPeriod);
}
void loop(){
  for (int i=0, i< 9, i++){ 
  //if we don't know the lenght we can put in counts of 9 the name of the array.lenght (in this case durations.lenght)
  //the parameter delay is a whole number, set of whole numbers or array
  /*the main function of the code that in other languages is known like main, in this case is named loop. This name is obligatory
  and it's a function that will repeat forever, until I disconnect the microcontroller*/
  /* durations[i] means:
  durations[0]
  durations[1]
  durations[2]
  durations[3]
  durations[4]
  durations[5]
  durations[6]
  durations[7]
  durations[8]
  
  This means: 200, 200, 200, 600, 600, 600, 200, 200, 200
              [0]  [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]
              
  We call this numbers with the flash function, because this function depends of one parameter, in this case delayPeriod, but we have replaced it with
  the array of durations*/
    flash(durations[i]);
    }
  delay(1400);
}