Thursday, 28 February 2008

Week 3

This week we got to grips with making and expanding our own Arduino code.

We were given some resources (switches, wire, resistor), and got into groups (resources were low again). We then made an Arduino setup with the switch and resistor so that when the switch is pressed, and the Arduino receives an input signal, an LED turns on.

After we had finished this simple setup (using a piece of code already in the example library), we then added another LED, switch and resistor to the circuit and expanded the code to include them so that when the other switch was pressed, that would turn on the other LED.

Here is the code:

int ledPin = 13; // choose the pin for the LED
int ledPinb = 12;
int inputPin = 2; // choose the input pin (for a pushbutton)
int inputPinb = 3;
int val = 0; // variable for reading the pin status

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(ledPinb, OUTPUT);
pinMode(inputPin, INPUT); // declare pushbutton as input
pinMode(inputPinb, INPUT);
}

void loop(){
val = digitalRead(inputPin); // read input value
val = digitalRead(inputPinb);
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}

if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPinb, LOW); // turn LED OFF
} else {
digitalWrite(ledPinb, HIGH); // turn LED ON
}
}

Here are some pictures of the first circuit...



Here is a picture of the second circuit...



Here is a video of the second circuit...



After having to modify existing code to adapt to my needs I feel far more confident in making physical interfaces. Now I feel I need to look at current developments in mainstream public interfaces to see how developers are pushing forward the current technology.

No comments: