Mental’s lab 4

Camera360_2013_9_27_093343 Camera360_2013_9_27_093355 WP_20130927_001

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>

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

void setup()
{
myservo.attach(9);  // attaches the servo on pin 9 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 it to use it with the servo (value between 0 and 180)
myservo.write(val);                  // sets the servo position according to the scaled value
delay(15);                           // waits for the servo to get there
}

Amy Xu’s Lab 3

In lab 3 I mostly experimented with gradients.

First, I used a nested for-loop to create a solid grid. The code for it is very similar to the one we did in class, but I used the line function instead of the point function. As the nested for-loops forms the squares by going down through the length of the canvas, then to the left for every square in the length, it also fills each square with a deeper shade of pink. I also varied the stroke weight and color of the lines in the grid so that the line thickens and darkens when you go down and to the right.

Next I hope to program this drawing so that the user can input: a) R, G, B value they want for the background color b) R, G, B value they want for the stroke color. This way they can customize their own background grid.

See the code and comments below for details.

—–
float d = 0.3;//the increase in R, G or B value with every iteration for background gradient
float x = 255; //R value
float y = 155; // G Value
float z = 200; // B value
float s = 0.5; // increase in R, G, B value with every iteration for stroke
float strokeSize = 0.01; // increase in stroke width for every iteration

void setup() {
size (640, 480);
background(33,67,88);
fill (x,y,z);
smooth();
for (int i=2; i<width; i=i+20) {
for (int j=2; j<height; j=j+20) {
rect(i,j,480,640);
fill(x-d,y-d,z-d);
stroke(255-s,255-s,255-s);
strokeWeight(strokeSize);
d = d+0.25; // adds 0.25 to the R, G, B value of background color
s = s+0.5; // adds 0.5 to the R,G,B value of the stroke color
strokeSize = strokeSize+0.01; // adds 0.01 to the stroke thickness
}
}
}

Final product!

Screen shot 2013-09-28 at 4.03.02 PM

Max’s Lab Documentation: Da Servo

 

 

 

 

 

 

 

Bork started out the morning with absolutely no idea of what to do.  Prospects of success seemed hopeless, particularly when he was surrounded by the intellectual giants of the likes of Bruce.  However, Bork decided to throw caution to the wind and press forth into the darkness of the unknown.  With the valuable aid of Lord Professor Matt, Bork found examples of the circuitry for connecting the Arduino with the potentiometer and servo online.  Next was the software: the beast, both shadow and flame, the programming.  Servo Lab 1 Despite seemingly insurmountable difficulties, Bork managed to get the code to work.  When the servo first turned it’s plasticky arm, the world seemed to open itself to the heavens and angels sang.  Lord Professor Matt had helped Bork to work the Servo.  However, Bork knew that he had to try more to understand the workings of the code.  So, at the suggestion of Lord Professor Matt, Bork tried to add in an analogRead function.  In the end it was a bloody battle, but Bork triumphed and smote the ruin of his electronic challenger upon the metaphorical mountainside.

Servo Lab 2

 

For any who would like to relive the workings of the Bork on this fateful morn, his workings and aimless wanderings can be found in the following code for Arduino:

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>

Servo myservo; // create servo object to control a servo
int analogPin = 3;
int potpin = 0; // analog pin used to connect the potentiometer
int val = 0; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); //setup serial (bork’s mindless add-on)
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(1500); // waits for the servo to get there
val = analogRead(potpin); //read input pin
Serial.println(val); //debug value
}

Xiaoyue’s Awesome Lab #3

Screen Shot 2013-09-27 at 11.13.48 AM

 

This is my playing with Processing.

The little blue bubbles are drawn by mouse clicking.

Here are my codes:

void setup(){
size(640,480);
background(0,20,100);
stroke(10,220,255);
int i;
int j;
noSmooth();
strokeWeight(3);
for (i=10;i<width;i=i+80){
for (j=10;j<height;j=j+60){
line(i,j,i+30,j+30);
}
}
fill(100,230,40);
noStroke();
ellipse(200,250,350,300);
fill(0,200,60);
arc(180,280,180,160,QUARTER_PI,TWO_PI,CHORD);
fill(0,200,60);
arc(450,140,200,120,3,9,PIE);
fill(0,150,20);
noStroke();
arc(160,280,120,120,2,PI);
fill(255,170,0);
arc(200,265,60,60,1.4,4.54);
fill(250,200,0);
arc(170,270,60,60,1,4.14);
fill(255,200,0);
arc(210,270,60,60,5,8.14);
noFill();
stroke(10,130,255);
strokeWeight(10);
curve(-100,0,60,80,450,50,380,180);
curve(200,800,200,440,600,430,300,300);
curve(300,500,400,300,630,330,700,130);
}
void draw(){
if(mousePressed){
fill(0,255,200);
ellipse(mouseX,mouseY,30,30);
}
}

Alicja’s Lab Documentation #4

Firstly, I looked for a way to construct my circuit so that the servo motor turns when I turn the knob on my potentiometer. I found a scheme here: http://arduino.cc/en/uploads/Tutorial/knob_BB.png, but then I decided  to construct 2 separate circuits, one for the potentiometer, which I connected to the 3.3V pin and one for the servo, which used the 5V pin.

Then I started working on the code. I began by adding the Servo library (Sketch>Import Library>Servo).  Then I started typing in the code. That’s what I came up with, using  help I found here: http://arduino.cc/en/Tutorial/Knob.

#include <Servo.h>

Servo xxx;
int potpin = 0;
int reading;

void setup () {
xxx.attach(9);
Serial.begin (9600);
}

void loop () {
Serial.println(reading);
reading = analogRead(potpin);
reading = map (reading, 0, 1023, 0, 179);
xxx.write(reading);
delay(15);
}

I added the command “Serial.println()”, which was not in the original code, because I wanted to make sure my potentiometer works properly.

The final effect:

alicjalab4

Susie’s Lab 4 Documentation

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>

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

void setup()
{
myservo.attach(9);  // attaches the servo on pin 9 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 it to use it with the servo (value between 0 and 180)
myservo.write(val);                  // sets the servo position according to the scaled value
delay(15);                           // waits for the servo to get there
}

 

20130927_092220 20130927_092226

 

 

http://arduino.cc/en/Tutorial/Knob