Crit Assignment #3&4
Break
Reading Assignment
Delusions of Dialog: Control and Choice in Interactive Art
By Jim Campbell
A paper discussing "art that uses a computer during the process of viewing and the relationship of this type of art the the structure of the computer."
Something to Think About
Final Project
Work on your own or with a partner?
The challenge is, we have only 5 more Arduinos. I need to know by next Tuesday (Feb. 10th). We'll have to do a lottery if more than five of you want to work on your own…
Working with Servomotors
A servomotor is a special kind of electric motor in which an electrical input determines the position of the rotating shaft of the motor. The kind we use usually rotate between 0 and 180 degrees and take a Pulse Width Modulated waveform as an input to determine the angle of rotation.
Originally these guys were used for radio-controlled model airplanes and such. Now they're used a lot for amateur robotics. There's a good explanation of how they work here.
- In Assignment #6 Servo Circuits you need to:
- Wire up a servo to the Arduino and write a program that controls it to turn to different angles that you specify.
- Create two variations on the program, one which will change the angle of the Servo in a rhythmic pattern and another which will change the angle of the Servo in a "random" or chaotic pattern. (More about chaotic vs. rythmic patterns in our next class.)
- Use a switch to change which variation of movement runs.
Controlling One Servo With A Trim Pot
Original Arduino Tutorial
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott
// Modified by Khazar, 11/2008
#include <Servo.h> // Include the Servo Library.
// Libraries are kept in the "hardware/libraries" subdirector of the
// Arduino application directory.
Servo myservo; // Create servo object to control a servo
int potpin = 0; // Analog pin used to connect the potentiometer
int val; // Variable to read the value from the analog pin
int servopin = 9; // Digital pin used to connect to the servo's control pin
void setup()
{
Serial.begin(9600);
myservo.attach(servopin); // Attaches the servo on servopin to the servo object
}
void loop()
{
val = analogRead(potpin); // Reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // Scale "val" to use it with the servo (value between 0 and 180)
// (See reference on "map" at http://arduino.cc/en/Reference/Map)
// map(value, fromLow, fromHigh, toLow, toHigh);
myservo.write(val); // Sets the servo position according to the scaled value
// the Servo library. It goes from 0 to 180 and corresponds to the
// degree of rotation.
Serial.println(val); // Send the value out thru the serial port.
delay(15); // Waits for the servo to get there.
}
Controlling One Servo To Sweep Back And Forth
Original Arduino Tutorial
Download timer-fader01.txt file
// Sweep
// by BARRAGAN
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Controlling Two Servos
// A sample of how to control 2 servos at the same time.
// Note – Apparently, the Servo library can handle this. The library on Arduino's playground at
// http://www.arduino.cc/playground/ComponentLib/Servotimer1 is really broken and generates
// a bunch of errors straight from the import command.
//
// Khazar, 11/08
#include <Servo.h>
Servo myservo1; // Create a servo object to control servo 1
Servo myservo2; // Create a servo object to control servo 2
int pos1 = 0; // Variable to hold the position of servo 1
int pos2 = 0; // Variable to hold the position of servo 2
long timer1Val = 100; // Variable to hold the timer for servo 1
long timer2Val = 100; // Variable to hold the timer for servo 2
int updown1 = 1; // Variable to hold the positive or negative change in angle
int updown2 = 1; // for servo 1, ditto for servo 2
void setup() {
myservo1.attach(9); // Attaches servo1 to pin 9;
myservo2.attach(10); // Attaches servo2 to pin 10;
Serial.begin(9600); // Turn on serial communication just in case...
timer1Val = millis(); // init timer 1;
timer2Val = millis(); // init timer 2;
}
void loop() {
// Timer 1 loop
if ((timer1Val + 100) <= millis()) {
myservo1.write(pos1); // do movement
Serial.print("Servo 1 position: ");
Serial.println(pos1); // check value
pos1 = pos1 + updown1; // increment or decrement value depending on updown's value
if (pos1 == 180) { // If pos1 reaches 180, change directon by making updown negative
updown1 = -1;
}
if (pos1 == 0) { // If pos1 reaches 0, change direction by making updown positive
updown1 = 1;
}
timer1Val = millis(); // Reset the timer
}
if ((timer2Val + 50) <= millis()) {
myservo2.write(pos2); // do movement
Serial.print("Servo 2 position: ");
Serial.println(pos2); // check value
pos2 = pos2 + updown2; // increment or decrement value depending on updown's value
if (pos2 == 180) { // If pos1 reaches 180, change directon by making updown negative
updown2 = -1;
}
if (pos2 == 0) { // If pos1 reaches 0, change direction by making updown positive
updown2 = 1;
}
timer2Val = millis(); // Reset the timer
}
}