Slides are here: http://mhellar.github.io/physcomp16
Grab the code here: http://bit.ly/2lNgyuu
We know what a computer looks like. It usually has a keyboard, monitor, CPU (Central Processing Unit), printer, and a mouse.These types of computers, like the Mac or PC, are primarily designed to communicate (or “interface”) with humans.
A microcontroller is a self-contained system with peripherals, memory and a processor that can be used as an embedded system. Most programmable microcontrollers that are used today are embedded in other consumer products or machinery including phones, peripherals, automobiles and household appliances for computer systems.
We call these devices “microcontrollers”. Micro because they’re small, and controller because they “control” machines, gadgets, whatever. They’re cool because, you can build a machine or device, write programs to control it and then let it work for you automatically.
“The two most important introductions for art in the past 20 years have been the Arduino and Processing,”
- Paola Antonelli, senior curator in the Department of Architecture and Design at the Museum of Modern Art.
Physical computing, in the broadest sense, means building interactive physical systems by the use of software and hardware that can sense and respond to the analog world.
In the past, using electronics meant having to deal with engineers, and building circuits one small component at a time.These issues kept creative people from experimenting with the medium directly. In recent years, micro- controllers have become cheaper and easier to use.
The progress that has been made with Arduino has been to bring these tools one step closer to the non expert allowing people to start building things after only two or three days of a workshop.
With Arduino, a designer or artist can get to know the basics of electronics and sensors very quickly and can start building prototypes with very little investment.
Greg Lynn, Scale model for RV Prototype 2012
These can either be inputs or outputs, which is defined in your code.
These dedicated analogue input pins take analog values (i.e., voltage readings from a sensor) and convert them into a number between 0 and 1023 we’ll look at this Thursday
There are actually six of the digital pins that can be reprogrammed for analog output we’ll look at this next class
These power pins are capable or providing 5.5 volts or 3.3 volts of power. Also there are two pins that are capable of providing ground connectons to any components that you attach to the controller.
The USB connector connects the controller to you computer allowing you to program it. The USB connection also provides power.
This first lesson won't really teach programming the Arduino. It’s meant to introduce you to building a basic electrical circuit.It will also get us prepped for building the rest of the exercises throughout the class.
An led is a directional component. -The long Lead is called the Anode is connected to the +5Volts -The short lead is called the Cathode and is connected to ground -As the electrical current passes through the LED produces light.
The 5 Volts from the Arduino is too much electricity for the LED and will burn it out.
We need to place a resistor in the circuit to lower the voltage
More on calculating resistance here: LED Resistor calculator:
This next lesson get you up and running with the Arduino software and uploading a sketch to the Arduino board. Once you've completed this step we can continue to the really interesting stuff, which is when we start writing our own sketches!
Parts are pretty much the same from the first excercise
From the tools menu -> Board->Arduino Uno
From the tools menu -> Serial Port >tty.usbmodem####
Hit the arrow to upload
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Arduino expects two functions to exists—one called
setup() and one called loop().
setup() is where you put all the code that you want to execute once at the beginning of your program
loop() contains the core of your program, which is executed over and over again. When you power up the board, the code runs; when you want to stop, you just turn it off.
// Example 01 : Blinking LED
A comment is a useful way for us to write little notes.The preceding title comment just reminds us that this program, Example 01, blinks an LED.
int LED = 13; // LED connected to // digital pin 13
We are defining a integer variable called LED as Arduino pin 13.
void setup()
This line tells Arduino that the next function will be called setup().
void setup()pinMode tells Arduino how to configure a certain pin. Digital pins can be used either as INPUT or OUTPUT. In this case, we need an output pin to control our LED, so we place the number of the pin and its mode inside the parentheses.
{ pinMode(LED, OUTPUT); // sets the digital // pin as output }
void loop()loop() is where you specify the main behavior of your interactive device. It will be repeated over and over again until you switch the board off.
{ // code here repeats over and over }
digitalWrite(LED,HIGH); //turns the LED on
As the comment says, digitalWrite() is able to turn on (or off) any pin that has been configured as an OUTPUT.
The first argument (in this case, LED) specifies which pin should be turned on or off (remember that LED is a constant value that refers to pin 13, so this is the pin that’s switched).
The second argument can turn the pin on (HIGH) or off (LOW).
Imagine that every output pin is a tiny power socket, like the ones you have on the walls of your apartment.American ones are 110V,and Arduino works at a more modest 5V.
The magic here is when software becomes hardware.When you write digitalWrite(LED, HIGH), it turns the output pin to 5 V, and if you connect an LED, it will light up.
So at this point in your code, an instruction in software makes something happen in the physical world by controlling the flow of electricity to the pin. We can translate this into something more visible with the LED as our
actuator.
delay(1000); // wait for a second
Pause the program for 1000ms = 1 second, leaving the LED on
digitalWrite(LED,LOW); //turns the LED off
As the comment says, digitalWrite() is able to turn on (or off) any pin that has been configured as an OUTPUT.
Set the pin LOW(off)
delay(1000); // wait for a second
Pause the program for 1000ms = 1 second, leaving the LED off
int led = 13;
int randval;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
randval = random(1000);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(randval); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(randval); // wait for a second
}
// Example 01 : Blinking LED
//
int LED = 13; // LED connected to
// digital pin 13
void setup()
{
pinMode(LED, OUTPUT); // sets the digital // pin as output
}
void loop()
{
for(int i = 1;i <=100; i++){
digitalWrite(LED, HIGH); // turns the LED on
delay(i); // waits for a second
digitalWrite(LED, LOW); // turns the LED off
delay(i); // waits for a second
}
}
Oh no, there's a bug in the code. Fix it so the Knight Rider can finish the mission