SlideShare a Scribd company logo
1 of 53
How to program software and objects
Dr. Francisco Pérez García
Institut Pompeu Fabra
Departament de Tecnologia
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
ASE2013 Dr.Pérez 3
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
TINKERING
ASE2013 Dr.Pérez 5
THE HACKER ATTITUDE FOR OUR STUDENTS
ASE2013 Dr.Pérez 6
WWW.PROCESSING.ORG
Library:
Nyatla Augmented Reality for Processing
Library
Open Computer Vision for Processing
WWW.ARDUINO.CC
Previous experiences: Contemporary Sciences and Research
http://www.youtube.com/watch?v=F_xkHOpMA9s
ASE2013 Dr.Pérez 15
ASE2013 Dr.Pérez 16
http://www.youtube.com/watch?v=O1MvwAw_MHkASE2013 Dr.Pérez 17
http://www.youtube.com/watch?v=FbuvE1n18ZE
ASE2013 Dr.Pérez 18
ASE2013 Dr.Pérez 19
ESPLORA
LEONARDO
Arduino Uno
ASE2013 Dr.Pérez 20
21
Comments
about the
code
Setup code
Define
variables
Loop code
Main
code
ASE2013 Dr.Pérez 22
ASE2013 Dr.Pérez 23
Transistor IRF530
DC motor
Diode 1N4001
Resistor
Arduino Uno
ARDUINO AND A DC MOTOR
AND THIS
SOURCE CODE
ASE2013 Dr.Pérez 24
const int transistorPin = 9; // connected to transistor gate
void setup() {
pinMode(transistorPin, OUTPUT);
}
void loop()
{ // loop= repeat again and again
digitalWrite(transistorPin, HIGH); // switch the motor on
delay(50); // wait for 50 miliseconds
digitalWrite(transistorPin, LOW); // switch the motor off
delay(5000); // wait for 5 seconds
}
SOURCE CODE FOR ARDUINO MOTOR
ASE2013 Dr.Pérez 25
MOTOR TO IRRADIATE A SURFACE VERY SLOWLY
ASE2013 Dr.Pérez 26
ASE2013 Dr.Pérez 27
http://www.youtube.com/watch?v=UQEtOJE02wE
ASE2013 Dr.Pérez 28
http://www.youtube.com/watch?v=e1iUjelHC6w
ASE2013 Dr.Pérez 29
Materials for
LDR 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
ASE2013 Dr.Pérez 30
LDR
Pulse width modulation
ASE2013 Dr.Pérez 31
ASE2013 Dr.Pérez 32
ASE2013 Dr.Pérez 33
Microcontroller ATMega328
Sensors
(analog inputs)
Brain
Sight
Touch
Taste
Smell
Hearing
Muscles
Nerves Wires, Circuit
Heart
Actuators
(analog
outputs)
ASE2013 Dr.Pérez 34
Analog to digital conversion
Analog sensor 0 to 5V
Sampling at Nyquist rate
Value of each sample
transformed to binary
format
ASE2013 Dr.Pérez 35
ASE2013 Dr.Pérez 36
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 assigned
a value*/
/*The setup function comes before the loop function, and everything
happens 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
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
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
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 colour
40
41
http://www.youtube.com/watch?v=hxkYNy4zTWc
ASE2013 Dr.Pérez 42
Playing music with Arduino
http://www.youtube.com/watch?v=YDL9WIVfS9w
43
ASE2013 Dr.Pérez 44
ASE2013 Dr.Pérez 45
Spychip technology?
46
SENSORS FOR
ARDUINO
ASE2013 Dr.Pérez 47
Transistor: to amplify the signal of the
sensor to the Arduino
48
Cloud internet of things platforms: www.cosm.com
Visualize and store sensor data online www.nimbits.com
www.thingspeak.com49
ASE2013 Dr.Pérez 50
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 €50
Sometimes very high import taxes from China!
51
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
ACKNOWLEGMENTS
The project «Contemporary Sciences and Research» (2012-2014)
belongs to the Integrated Plan for Foreign Languages of Departament
Of Education, Government of Catalonia
More info at www.tecnologies.net
53

More Related Content

Similar to How to program software and objects

SKAD Electronics Training Manual.pdf
SKAD Electronics Training Manual.pdfSKAD Electronics Training Manual.pdf
SKAD Electronics Training Manual.pdfKadiriIbrahim2
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoBrian Huang
 
LEDs and DIPs Switches
LEDs and DIPs SwitchesLEDs and DIPs Switches
LEDs and DIPs SwitchesBach Nguyen
 
Android Meets A BeagleBone In The IoT World
Android Meets A BeagleBone In The IoT WorldAndroid Meets A BeagleBone In The IoT World
Android Meets A BeagleBone In The IoT WorldLars Gregori
 
Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011Jordi Valverde
 
Porte à puce - Automatic Door based on Arduino UNO R3
Porte à puce - Automatic Door based on Arduino UNO R3Porte à puce - Automatic Door based on Arduino UNO R3
Porte à puce - Automatic Door based on Arduino UNO R3Meifani Sumadijaya
 
CipherKey Algorithm
CipherKey AlgorithmCipherKey Algorithm
CipherKey Algorithmijtsrd
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduinoSravanthi Sinha
 
Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3Ziddan Kundrat
 
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...Faqih Fadhila Ardiansyah
 
Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3Meifani Sumadijaya
 
SMART LAMP WITH A GSM MODULE SIM 800 L
SMART LAMP WITH A GSM MODULE SIM 800 LSMART LAMP WITH A GSM MODULE SIM 800 L
SMART LAMP WITH A GSM MODULE SIM 800 LArisa trirahayu
 
SMART LAMP WITH A GSM MODULE SIM 800L
SMART LAMP WITH A GSM MODULE SIM 800LSMART LAMP WITH A GSM MODULE SIM 800L
SMART LAMP WITH A GSM MODULE SIM 800LArisaTR
 
Smart lamp with gsm modul sim800 l
Smart lamp with gsm modul sim800 lSmart lamp with gsm modul sim800 l
Smart lamp with gsm modul sim800 lrikkjo29
 

Similar to How to program software and objects (20)

Arduino2013
Arduino2013Arduino2013
Arduino2013
 
SKAD Electronics Training Manual.pdf
SKAD Electronics Training Manual.pdfSKAD Electronics Training Manual.pdf
SKAD Electronics Training Manual.pdf
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and Arduino
 
LEDs and DIPs Switches
LEDs and DIPs SwitchesLEDs and DIPs Switches
LEDs and DIPs Switches
 
Android Meets A BeagleBone In The IoT World
Android Meets A BeagleBone In The IoT WorldAndroid Meets A BeagleBone In The IoT World
Android Meets A BeagleBone In The IoT World
 
Arduino
ArduinoArduino
Arduino
 
Arduino
ArduinoArduino
Arduino
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
 
Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011
 
Porte à puce
Porte à pucePorte à puce
Porte à puce
 
Porte à puce - Automatic Door based on Arduino UNO R3
Porte à puce - Automatic Door based on Arduino UNO R3Porte à puce - Automatic Door based on Arduino UNO R3
Porte à puce - Automatic Door based on Arduino UNO R3
 
Porte à puce
Porte à pucePorte à puce
Porte à puce
 
CipherKey Algorithm
CipherKey AlgorithmCipherKey Algorithm
CipherKey Algorithm
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
 
Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3
 
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...
 
Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3
 
SMART LAMP WITH A GSM MODULE SIM 800 L
SMART LAMP WITH A GSM MODULE SIM 800 LSMART LAMP WITH A GSM MODULE SIM 800 L
SMART LAMP WITH A GSM MODULE SIM 800 L
 
SMART LAMP WITH A GSM MODULE SIM 800L
SMART LAMP WITH A GSM MODULE SIM 800LSMART LAMP WITH A GSM MODULE SIM 800L
SMART LAMP WITH A GSM MODULE SIM 800L
 
Smart lamp with gsm modul sim800 l
Smart lamp with gsm modul sim800 lSmart lamp with gsm modul sim800 l
Smart lamp with gsm modul sim800 l
 

More from Francisco Perez

More from Francisco Perez (20)

Coding tools
Coding toolsCoding tools
Coding tools
 
Analysing the Universe
Analysing the UniverseAnalysing the Universe
Analysing the Universe
 
Contaminants
ContaminantsContaminants
Contaminants
 
Docking 1
Docking 1Docking 1
Docking 1
 
Campus Ítaca UAB
Campus Ítaca UABCampus Ítaca UAB
Campus Ítaca UAB
 
Vivid library powerpoint
Vivid library powerpointVivid library powerpoint
Vivid library powerpoint
 
Multicultural theatres
Multicultural theatresMulticultural theatres
Multicultural theatres
 
D'ESO a CF 2019
D'ESO a CF 2019D'ESO a CF 2019
D'ESO a CF 2019
 
Debating in Latvia
Debating in LatviaDebating in Latvia
Debating in Latvia
 
Projecte amb institut xinès
Projecte amb institut xinèsProjecte amb institut xinès
Projecte amb institut xinès
 
Projecte Erasmus+
Projecte Erasmus+Projecte Erasmus+
Projecte Erasmus+
 
Visit Jeonbuk High School (Corea)
Visit Jeonbuk High School (Corea)Visit Jeonbuk High School (Corea)
Visit Jeonbuk High School (Corea)
 
Guia pràctica per fer un bon tr btx 20 consells
Guia pràctica per fer un bon tr btx 20 consellsGuia pràctica per fer un bon tr btx 20 consells
Guia pràctica per fer un bon tr btx 20 consells
 
Essay
EssayEssay
Essay
 
Presentation for Portugal
Presentation for PortugalPresentation for Portugal
Presentation for Portugal
 
Sant Jordi 2018
Sant Jordi 2018Sant Jordi 2018
Sant Jordi 2018
 
Ponderacions catalunya pau 2018
Ponderacions catalunya pau 2018Ponderacions catalunya pau 2018
Ponderacions catalunya pau 2018
 
Des d'ESO a CCFF 2018
Des d'ESO a CCFF 2018Des d'ESO a CCFF 2018
Des d'ESO a CCFF 2018
 
Class lists
Class listsClass lists
Class lists
 
Families are reading the world classic novels
Families are reading  the world classic novelsFamilies are reading  the world classic novels
Families are reading the world classic novels
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

How to program software and objects

  • 1. How to program software and objects Dr. Francisco Pérez García Institut Pompeu Fabra Departament de Tecnologia
  • 2. 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
  • 4. 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
  • 6. THE HACKER ATTITUDE FOR OUR STUDENTS ASE2013 Dr.Pérez 6
  • 7.
  • 8.
  • 9.
  • 14.
  • 15. Previous experiences: Contemporary Sciences and Research http://www.youtube.com/watch?v=F_xkHOpMA9s ASE2013 Dr.Pérez 15
  • 23. ASE2013 Dr.Pérez 23 Transistor IRF530 DC motor Diode 1N4001 Resistor Arduino Uno ARDUINO AND A DC MOTOR AND THIS SOURCE CODE
  • 24. ASE2013 Dr.Pérez 24 const int transistorPin = 9; // connected to transistor gate void setup() { pinMode(transistorPin, OUTPUT); } void loop() { // loop= repeat again and again digitalWrite(transistorPin, HIGH); // switch the motor on delay(50); // wait for 50 miliseconds digitalWrite(transistorPin, LOW); // switch the motor off delay(5000); // wait for 5 seconds } SOURCE CODE FOR ARDUINO MOTOR
  • 25. ASE2013 Dr.Pérez 25 MOTOR TO IRRADIATE A SURFACE VERY SLOWLY
  • 29. ASE2013 Dr.Pérez 29 Materials for LDR 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
  • 33. ASE2013 Dr.Pérez 33 Microcontroller ATMega328 Sensors (analog inputs) Brain Sight Touch Taste Smell Hearing Muscles Nerves Wires, Circuit Heart Actuators (analog outputs)
  • 34. ASE2013 Dr.Pérez 34 Analog to digital conversion Analog sensor 0 to 5V Sampling at Nyquist rate Value of each sample transformed to binary format
  • 37. 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 assigned a value*/ /*The setup function comes before the loop function, and everything happens 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
  • 38. 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
  • 39. 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
  • 40. 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 colour 40
  • 43. Playing music with Arduino http://www.youtube.com/watch?v=YDL9WIVfS9w 43
  • 46. 46
  • 48. Transistor: to amplify the signal of the sensor to the Arduino 48
  • 49. Cloud internet of things platforms: www.cosm.com Visualize and store sensor data online www.nimbits.com www.thingspeak.com49
  • 51. 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 €50 Sometimes very high import taxes from China! 51
  • 52. 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
  • 53. ACKNOWLEGMENTS The project «Contemporary Sciences and Research» (2012-2014) belongs to the Integrated Plan for Foreign Languages of Departament Of Education, Government of Catalonia More info at www.tecnologies.net 53