Skip to content

4. Embedded programming

Over the course of this week, I focused on establishing the concept for my final project and began familiarizing myself with the documentation procedures.

MKR WiFi 1010


For more info about board go to Zainab website

This is the process I follow in the Arduino IDE to choose the board and port:

Task 1

Easy Mode: Blink my led but have your blink delay periods randomized values 1 sec and 5 sec. First I select the board and port:


/*
  Blink

// the setup function runs once when you press reset or power the board
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() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

// To Change the time change the # of second


Task 2

medium Mode: pre code my microcontroller to send my name in Morse code


int ledPin = 6;
int dotTime = 500;
int dashTime = 1000;
int letterSpace = 1000;
int wordSpace = 2000;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  blink(".-");
  delay(letterSpace);
  blink(".-..");
  delay(letterSpace);
  blink("..");
  delay(wordSpace);
}

void blink(String code) {
  for (int i = 0; i < code.length(); i++) {
    if (code.charAt(i) == '.') {
      digitalWrite(ledPin, HIGH);
      delay(dotTime);
      digitalWrite(ledPin, LOW);
      delay(dotTime);
    } else if (code.charAt(i) == '-') {
      digitalWrite(ledPin, HIGH);
      delay(dashTime);
      digitalWrite(ledPin, LOW);
      delay(dotTime);
    }
  }
}



Task 3

Hard mode: select the duration of the light being on and off while the program is running by entering it in the serial monitor


int ledPin = 6;
int onTime = 500;
int offTime = 500;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    String input = Serial.readStringUntil('\n');
    input.trim();
    if (input.startsWith("onTime:")) {
      onTime = input.substring(7).toInt();
    } else if (input.startsWith("offTime:")) {
      offTime = input.substring(8).toInt();
    }
  }

  digitalWrite(ledPin, HIGH);
  delay(onTime);
  digitalWrite(ledPin, LOW);
  delay(offTime);
}

Last update: September 11, 2023