Skip to content

9. Embedded programming

This week we had to program the board we manufactured two weeks ago.

Connection

First of all I planned since the week “electronic production” to connect my board via the serial-UPDI

Then to write the code I’m using Arduino’s IDE. But with the default installation you can’t communicate with an Attiny. To be able to do that you have to install a new core.

In Files > Preferences add this URL to additional board manager : http://drazzy.com/package_drazzy.com_index.json

Now you have to go to Tools > Boards > Boards Manager search “ megatinycore “ and install it.

The final step is to set the correct parameters for your board, port and how you choose to program it.

First program

I simply ask the leds to glow when we push the button.

const int button = A6; 
const int led =  A7; 


void setup() {

  pinMode(led, OUTPUT);
  pinMode(button, INPUT);

}

void loop() {

  if (digitalRead(button) == HIGH) {
    digitalWrite(led, HIGH);
  }

  else digitalWrite(led, LOW);

  delay(100);

}

Morse code

Since it was too easy I think about what we could do with only a led and a button. The answer was morse code.

I start by writing a writing a function for every letter as shown in the few examples below :

void dot() {

  digitalWrite(LED, HIGH);
  delay(unit);                       
  digitalWrite(LED, LOW);

}

void dash() {

  digitalWrite(LED, HIGH);
  delay(3*unit);                       
  digitalWrite(LED, LOW);

}



void a(){

  dot();
  delay(space_in_letter);
  dash();

}

void b(){

  dash();
  delay(space_in_letter);
  dot();
  delay(space_in_letter);
  dot();
  delay(space_in_letter);
  dot();

}

My first main code to try these functions look like that :

void loop() {


  if ( digitalRead(Button) == HIGH ){

    f(); 
    delay(space_between_letters);  
    a(); 
    delay(space_between_letters);
    b(); 
    delay(space_between_letters);
    a(); 
    delay(space_between_letters);
    c(); 
    delay(space_between_letters);
    a(); 
    delay(space_between_letters);
    d(); 
    delay(space_between_letters);
    e(); 
    delay(space_between_letters);
    m(); 
    delay(space_between_letters);
    y(); 
    delay(space_between_words);

  }

  delay(500);

}

Last update: April 15, 2021