Assignment 4 – Arduino Continued

Today is dedicated to the Arduinos.

Everyone picks a chapter in the Arduino Projects book. Last week I have to say I didn’t quite get everything that we did to get a working result. To understand the basics better I choose the first chapter. This also deals with lights, a component I will need for my final project.

I now get to know how the breadboard is structured. The two outer dots are each connected to the ones below them. The dots in the middle are connected within rows.

 

Light a LED with two switches (Parallel and Series Circuit)

The first task is similar to what I did in the last lesson: this time instead of one I use two switches to light a LED. I follow the instructions in the book and this time understand how it works. First I put the buttons in a series and then in a parallel circuit. In the series circuit it is necessary that both buttons are pressed to light the LED. In the parallel one it suffices to press only one.

DSC_3094

The series circuit. Both buttons need to be pressed in order for the LED to light up.

Spaceship Interface

I am now more comfortable with the electronics and start with the next chapter. Here I build a « Spaceship Interface ». With three LEDs and a button. As long as the button is pressed the two red LEDs blink in an alternating fashion. When the button is first pressed and when it is released the green LED lights up once.

DSC_3096

The code is as follows:


int switchState = 0;

void setup() {

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);

}

void loop() {

switchState = digitalRead(2);
if (switchState == LOW){
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
} else {
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);

delay(250);

digitalWrite(4,HIGH);
digitalWrite(5,LOW);

delay(250);

}

 

 

 

Publicités
Publié dans Uncategorized
Web2PDF