Lina Maria Giraldo's Blog

Multimedia Artist and ITP Student

Archive for the ‘Analog Output’ tag

Week 4 Analog Output

with one comment

Bellow is more documentation of my Analog Output Lab. I though it would be nice for future reference to have a better angle of the wires and Arduino. Also it was important to make interact real people with my chicken fighters. I hope you enjoy:

My wires:

Here is the code:

/*

Servo control from an analog input using the Arduino Servo library

 

This example code uses the Arduino Servo library which comes packaged with the Arduino software.

 

In order to make this work, you must include the Servo.h library file, create an instance of the Servo object, 

attach a digital PWM pin to the Servo object, and then write an analog value to the Servo object to set its 

position.

 

The difference between using the Servo library and the older method of pulsing a digital pin is that the library

handles a lot of the work for you. You no longer need to figure out the translation between pulse length and position. 

You now can simply specify the angle you’d like your servo to be at and it will turn to that position.

 

Please note, unlike the older pulsing method you MUST use a digital PWM pin or it will not work.

 

by Rory Nugent

Created 20 Jan. 2009

*/

 

#include <Servo.h>      // include the servo library

 

Servo servoMotor;  

 

Servo servoMotor2;// creates an instance of the servo object to control a servo

 

int analogPin1 = 0;      // the analog pin that the sensor is on

int analogValue1 = 0;    // the value returned from the analog sensor

int analogPin2 = 1;      // the analog pin that the sensor is on

int analogValue2 = 0;    // the value returned from the analog sensor

 

 

int servoPin1 = 9;       // Control pin for servo motor, must be a PWM pin

int servoPin2 = 10;       // Control pin for servo motor, must be a PWM pin

 

void setup() { 

  servoMotor.attach(servoPin1);  // attaches the servo on pin 9 to the servo object

  servoMotor2.attach(servoPin2);  // attaches the servo on pin 9 to the servo object

 

 

void loop() 

  analogValue1 = analogRead(analogPin1);                 // read the analog input (value between 0 and 1023)

  analogValue1 = map(analogValue1, 0, 1023, 0, 179);     // map the analog value (0 – 1023) to the angle of the servo (0 – 179)

  servoMotor.write(analogValue1);   // write the new mapped analog value to set the position of the servo

 analogValue2 = analogRead(analogPin2);                 // read the analog input (value between 0 and 1023)

  analogValue2 = map(analogValue2, 0, 1023, 0, 179);     // map the analog value (0 – 1023) to the angle of the servo (0 – 179)

  servoMotor2.write(analogValue2);   // write the new mapped analog value to set the position of the servo

 

  delay(15);                                           // waits for the servo to get there 

}

 

 

 

 

 

Bellow is final project in the Analog Output Lab

Bellow is step by step the development of the lab

 


Written by admin

February 17th, 2009 at 11:22 pm