Programming for Sculptors

ARTS-A0407 – Digital Sculpture 3 (2cr)

Lecture 4, 22.1.2020

Today:

  • Servo motors and Arduino
  • if-else
  • Using serial monitor

Examples: Grönlund-Nisunen

Examples: Zimoun

Examples: High school student Lauttasaaren yhteiskoulu

Motors 101

Geared DC motor

DC motor

Servo motor

Stepper motor

Solenoid

+ pups ect.

May have different voltages!

Controlling a servo vs. a DC motor

An Arduino motor shield makes things easy

Inside a servo

Serial.println(): how to debug your code

int analogValue = 0;    // variable to hold the analog value

void setup() {
  // open the serial port at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog input on pin 0:
  analogValue = analogRead(0);

  // print it out:
  Serial.println(analogValue);   
  
  // delay 10 milliseconds before the next reading:
  delay(10);
}

Controlling a servo with an Arduino

(Note: Servos can rotate ~180° or continusly. Servos can have different voltages. Arduino can deliver 5V and low current. On bigger servos and motors you will need to use external power supply for the motor)

if-else

if (condition) {
  //statement(s)
}
if (condition) {
	//statement
} else {
	//other statement
}
if (condition) {
	//statement
} if else (another_condition) {
	//other statement
} else {
	//yet another statement
}
//All these operations return true of false 
// true/flase, 0/1, HIGH/LOW are all synonyms

x == y // x is equal to y
x != y // x is not equal to y
x <  y // x is less than y
x >  y // x is greater than y
x <= y // x is less than or equal to y
x >= y // x is greater than or equal to y

// x is not equal to y OR x is not equal to z
x != y || x != z 

// x is not equal to y AND x is not equal to z
x != y && x != z 

Write a program that turns the servo to either 0° or 180° based on the potentiometer value

Boolean data type

bool var = true;

var = !var;

var = 1 < 10;

var = 1 < 10 || 10 < 1

var = 1 < 10 && 10 < 1

Advanced: DC motors

Advanced: use capacitive sensing

How to install additional library: https://www.arduino.cc/en/guide/libraries

Made with Slides.com