top of page

DSL810

Special Topics in Design
Microcontroller Programming

Ardino code for "Write your first name by switching 9 LEDs on/off and push buttons such that: With press of one push button, the letters of the name blink every 1000 ms."

​

So for this assignment all we needed was an Aurdino Uno, 9 LED bulbs, 9 Resistors (220 ohms), 2 Push switches, a Breadboard and Jumperwires (male to male).

​

The aurdino code for this is :-

​

int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int ledPin5 = 6;
int ledPin6 = 7;
int ledPin7 = 8;
int ledPin8 = 9;
int ledPin9 = 10;
int buttonApin = 11;
int buttonBpin = 12;
int duration=1000;

char letter = 0;
int n=5;

void setup() 
{
    // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);  
  pinMode(buttonBpin, INPUT_PULLUP);  
}


void loop() {

   if (digitalRead(buttonApin) == LOW)
  {
    A();
    delay(duration);
    N();
    delay(duration);
    O();
    delay(duration);
    U();
    delay(duration);
    S();
    delay(duration);
    H();
    delay(duration);
    K();
    delay(duration);
    A();
    
  }

  if (digitalRead(buttonBpin) == LOW)
  {
    for(int n= 0; n<5; n++)
    {
      ALLUP();
      delay(duration);
      ALLDOWN();
      delay(duration);
    }
  }

  
  if (Serial.available() > 0) {    // is a character available?
    letter = Serial.read();       // get the character
  
    // check if a number was received
    if (letter == 'A') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      A();/*letter A*/
      delay(duration);
    }
        if (letter == 'N') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      N();/*letter N*/
      delay(duration);
    }
        if (letter == 'O') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      O();/*letter O*/
      delay(duration);
    }
    if (letter == 'U') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      U();/*letter U*/
      delay(duration);
    }
    if (letter == 'S') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      S();/*letter S*/
      delay(duration);
    }
    if (letter == 'H') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      H();/*letter H*/
      delay(duration);
    }
    if (letter == 'K') {
      Serial.print("Letter received = ");
      Serial.println(letter);
      K();/*letter K*/
      delay(duration);
    }
  }

 

}

void A(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, HIGH);
    digitalWrite(ledPin9, HIGH);
}
void N(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, LOW);
    digitalWrite(ledPin9, HIGH);
}
void O(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, HIGH);
    digitalWrite(ledPin9, HIGH);
}
void U(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, LOW);
    digitalWrite(ledPin9, HIGH);
}
void S(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, HIGH);
    digitalWrite(ledPin9, HIGH);
}
void H(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, LOW);
    digitalWrite(ledPin9, HIGH);
}
void K(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, LOW);
    digitalWrite(ledPin9, HIGH);
}
void ALLUP(){
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, HIGH);
    digitalWrite(ledPin9, HIGH);
}

void ALLDOWN(){
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW);
    digitalWrite(ledPin9, LOW);
}

Capture.PNG
IMG_20190918_150748.jpg

The ideal connections of the aurdino with all the components such that the 9 LED bulbs work as one letter.

The jumper wires connected to the Aurdino Uno.

IMG_20190918_150612.jpg

The connections of all the components on the bread board.

IMG_20190918_150528.jpg

The LEDs on the board working after being connected and running the code.

bottom of page