Transcript
Page 1: How to program software and objects

How to program software and objects

Dr. Francisco Pérez GarcíaInstitut Pompeu FabraDepartament de Tecnologia

Page 2: How to program software and objects

Donat el caràcter i la finalitat exclusivament docent i eminentment il·lustrativa de les explicacions a classe d'aquesta presentació, l’autor s’acull a l’article 32 de la Llei de Propietat Intel·lectual vigent respecte de l'ús parcial d'obres alienes com ara imatges, gràfics o altre material contingudes en les diferents diapositives

Page 3: How to program software and objects

ASE2013 Dr.Pérez 3

Page 4: How to program software and objects

WHY PROGRAMMING?

• Computer science is no more about computers than astronomy is about telescopes. Edsger Dijkstra

• The computer revolution hasn’t happened yet. Allan Kay

• Debugging is the essence of intellectual activity. Seymour Pappert

ASE2013 Dr.Pérez 4

Page 5: How to program software and objects

TINKERING

ASE2013 Dr.Pérez 5

Page 6: How to program software and objects

THE HACKER ATTITUDE FOR OUR STUDENTS

ASE2013 Dr.Pérez 6

Page 7: How to program software and objects
Page 8: How to program software and objects
Page 9: How to program software and objects
Page 10: How to program software and objects

WWW.PROCESSING.ORG

Page 11: How to program software and objects

Library:Nyatla Augmented Reality for Processing

Page 12: How to program software and objects

LibraryOpen Computer Vision for Processing

Page 13: How to program software and objects

WWW.ARDUINO.CC

Page 14: How to program software and objects
Page 15: How to program software and objects

Previous experiences: Contemporary Sciences and Research

http://www.youtube.com/watch?v=F_xkHOpMA9sASE2013 Dr.Pérez 15

Page 16: How to program software and objects

ASE2013 Dr.Pérez 16

Page 17: How to program software and objects

http://www.youtube.com/watch?v=O1MvwAw_MHkASE2013 Dr.Pérez 17

Page 18: How to program software and objects

http://www.youtube.com/watch?v=FbuvE1n18ZE

ASE2013 Dr.Pérez 18

Page 19: How to program software and objects

ASE2013 Dr.Pérez 19

ESPLORA

LEONARDO

Page 20: How to program software and objects

Arduino Uno

ASE2013 Dr.Pérez 20

Page 21: How to program software and objects

21

Comments about thecode

Setup codeDefine variables

Loop codeMain code

Page 22: How to program software and objects

ASE2013 Dr.Pérez 22

Page 23: How to program software and objects

ASE2013 Dr.Pérez 23

Transistor IRF530DC motor

Diode 1N4001Resistor

Arduino Uno

ARDUINO AND A DC MOTOR

AND THISSOURCE CODE

Page 24: How to program software and objects

ASE2013 Dr.Pérez 24

const int transistorPin = 9; // connected to transistor gate

void setup() {pinMode(transistorPin, OUTPUT);}

void loop() { // loop= repeat again and againdigitalWrite(transistorPin, HIGH); // switch the motor ondelay(50); // wait for 50 milisecondsdigitalWrite(transistorPin, LOW); // switch the motor offdelay(5000); // wait for 5 seconds

}

SOURCE CODE FOR ARDUINO MOTOR

Page 25: How to program software and objects

ASE2013 Dr.Pérez 25

MOTOR TO IRRADIATE A SURFACE VERY SLOWLY

Page 26: How to program software and objects

ASE2013 Dr.Pérez 26

Page 27: How to program software and objects

ASE2013 Dr.Pérez 27

http://www.youtube.com/watch?v=UQEtOJE02wE

Page 28: How to program software and objects

ASE2013 Dr.Pérez 28

http://www.youtube.com/watch?v=e1iUjelHC6w

Page 29: How to program software and objects

ASE2013 Dr.Pérez 29

Materials forLDR and LED-RGB using Arduino

● -4 resistor 220 Ω● -1 LDR sensor● -1 RGB LED● -1 potenciometer● -1 Arduino Uno● - Wire● - Breadboard● - USB wire AB type or microUSB for Arduino Leonardo

Page 30: How to program software and objects

ASE2013 Dr.Pérez 30

LDR

Page 31: How to program software and objects

Pulse width modulation

ASE2013 Dr.Pérez 31

Page 32: How to program software and objects

ASE2013 Dr.Pérez 32

Page 33: How to program software and objects

ASE2013 Dr.Pérez 33

Microcontroller ATMega328

Sensors(analog inputs)

Brain

Sight

Touch

Taste

SmellHearing

Muscles

Nerves Wires, Circuit

Heart

Actuators(analogoutputs)

Page 34: How to program software and objects

ASE2013 Dr.Pérez 34

Analog to digital conversion

Analog sensor 0 to 5V

Sampling at Nyquist rate

Value of each sample transformed to binaryformat

Page 35: How to program software and objects

ASE2013 Dr.Pérez 35

Page 36: How to program software and objects

ASE2013 Dr.Pérez 36

Page 37: How to program software and objects

SOURCE CODE: RGB-LED colour change depending on light level

int valueLDR = 1;

int ledRed = 9;

int ledGreen=10;

int ledBlue=11;

int pinLDR = 1;

//3 outputs for each RGB colour: red, green and blue

void setup(){

pinMode(ledRed, OUTPUT);

pinMode(ledGreen, OUTPUT);

pinMode(ledBlue, OUTPUT);

analogReference(EXTERNAL);

}

/*First we define the variable name as integer and it is assigneda value*/

/*The setup function comes before the loop function, and everythinghappens inside the curly backets*/

/*Outputs are declared in setup, this is done by usingthe pinMode function, in this particular example we declare numbers 9, 10 and 11 as OUTPUT (in capital letters)*/

// or /*Comment*/ can be anywhere, do not affect code, help others

ASE2013 Dr.Pérez 37

Page 38: How to program software and objects

void loop() {

valueLDR = analogRead(pinLDR);

if(valueLDR >= 1023){

digitalWrite(ledRed, 128);

digitalWrite(ledGreen, 0);

digitalWrite(ledBlue, 0);

// digitalWrite to obtain different colours

}

else if((valueLDR >= 959) & (valueLDR < 1023)){

digitalWrite(ledRed, 255);

digitalWrite(ledGreen, 0);

digitalWrite(ledBlue, 0);

}

The “void” in the header is what the function will return (or spit out) when it happens, in this case it returns nothing so it is void

38

Page 39: How to program software and objects

else if((valueLDR >= 895) & (valueLDR < 959)){

digitalWrite(ledRed, 255);

digitalWrite(ledGreen, 128);

digitalWrite(ledBlue, 0);}

else if((valueLDR >= 831) & (valueLDR < 895)){

digitalWrite(ledRed, 255);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 0);}

else if((valueLDR >= 767) & (valueLDR < 831)){

digitalWrite(ledRed, 255);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 128);}

else if((valueLDR >= 703) & (valueLDR < 767)){

digitalWrite(ledRed, 128);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 255);

}

else if((valueLDR >= 639) & (valueLDR < 703)){

digitalWrite(ledRed, 128);

digitalWrite(ledGreen, 128);

digitalWrite(ledBlue, 255);}

else if((valueLDR >= 575) & (valueLDR < 639)){

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 128);

digitalWrite(ledBlue, 255);}

else if((valueLDR >= 511) & (valueLDR < 575)){

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 0);

digitalWrite(ledBlue, 255);}

else if((valueLDR >= 447) & (valueLDR < 511)){

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 0);

digitalWrite(ledBlue, 128);

}

else if((valueLDR >= 383) & (valueLDR < 447)){

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 128);

digitalWrite(ledBlue, 0);}

else if((valueLDR >= 319) & (valueLDR < 383)){

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 0);}

else if((valueLDR >= 255) & (valueLDR < 319)){

digitalWrite(ledRed, 128);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 0);}

else if((valueLDR >= 191) & (valueLDR < 255)){

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 128);

}

39

Page 40: How to program software and objects

else if((valueLDR >= 127) & (valueLDR < 191))

{

digitalWrite(ledRed, 128);

digitalWrite(ledGreen, 255);

digitalWrite(ledBlue, 128);}

else if((valueLDR >= 63) & (valueLDR < 127))

{

digitalWrite(ledRed, 128);

digitalWrite(ledGreen, 128);

digitalWrite(ledBlue, 128);}

else if((valueLDR >=0) & (valueLDR < 63)){

digitalWrite(ledRed, 55);

digitalWrite(ledGreen, 55);

digitalWrite(ledBlue, 55); }

else

{

digitalWrite(ledRed, 0);

digitalWrite(ledGreen, 0);

digitalWrite(ledBlue, 0);

}

}

void color(int red, int green, int blue)

{

analogWrite(ledRed, 255-red);

analogWrite(ledGreen, 255-green);

analogWrite(ledBlue, 255-blue);

// PWM for every colour40

Page 41: How to program software and objects

41

http://www.youtube.com/watch?v=hxkYNy4zTWc

Page 42: How to program software and objects

ASE2013 Dr.Pérez 42

Page 43: How to program software and objects

Playing music with Arduinohttp://www.youtube.com/watch?v=YDL9WIVfS9w

43

Page 44: How to program software and objects

ASE2013 Dr.Pérez 44

Page 45: How to program software and objects

ASE2013 Dr.Pérez 45

Spychip technology?

Page 46: How to program software and objects

46

Page 47: How to program software and objects

SENSORS FOR ARDUINO

ASE2013 Dr.Pérez 47

Page 48: How to program software and objects

Transistor: to amplify the signal of the sensor to the Arduino

48

Page 49: How to program software and objects

Cloud internet of things platforms: www.cosm.comVisualize and store sensor data online www.nimbits.com

www.thingspeak.com49

Page 50: How to program software and objects

ASE2013 Dr.Pérez 50

Page 51: How to program software and objects

Approximate pricing

• Arduino Leonardo €25• Resistors, LEDs, LDR around €5• Breadboard €10• MQ sensors (CO, CH4, etc) €5 each• MG811 (CO2 sensor) €50• Voice recognition shield €60• Arduino for Android €50Sometimes very high import taxes from China!

51

Page 52: How to program software and objects

Resources• www.arduino.cc• http://blocs.xtec.cat/mecanica• www.sparkfun.com• www.fritzing.org• www.buildinginternetofthings.com• www.atmel.com/avr• www.avrfreaks.net• www.mcselec.com• www.argentdata.com

52

Page 53: How to program software and objects

ACKNOWLEGMENTS

The project «Contemporary Sciences and Research» (2012-2014)belongs to the Integrated Plan for Foreign Languages of DepartamentOf Education, Government of Catalonia

More info at www.tecnologies.net

53


Recommended