How to program software and objects

688 views

Published on

Science Week 2013 Activity
Centre Cultural de Martorell
Integrated Plan for Foreign Languages
Institut Pompeu Fabra

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
688
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

How to program software and objects

  1. 1. How to program software and objects Dr. Francisco Pérez García Institut Pompeu Fabra Departament de Tecnologia
  2. 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
  3. 3. ASE2013 Dr.Pérez 3
  4. 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
  5. 5. TINKERING ASE2013 Dr.Pérez 5
  6. 6. THE HACKER ATTITUDE FOR OUR STUDENTS ASE2013 Dr.Pérez 6
  7. 7. WWW.PROCESSING.ORG
  8. 8. Library: Nyatla Augmented Reality for Processing
  9. 9. Library Open Computer Vision for Processing
  10. 10. WWW.ARDUINO.CC
  11. 11. Previous experiences: Contemporary Sciences and Research http://www.youtube.com/watch?v=F_xkHOpMA9s ASE2013 Dr.Pérez 15
  12. 12. ASE2013 Dr.Pérez 16
  13. 13. http://www.youtube.com/watch?v=O1MvwAw_MHkASE2013 Dr.Pérez 17
  14. 14. http://www.youtube.com/watch?v=FbuvE1n18ZE ASE2013 Dr.Pérez 18
  15. 15. ASE2013 Dr.Pérez 19 ESPLORA LEONARDO
  16. 16. Arduino Uno ASE2013 Dr.Pérez 20
  17. 17. 21 Comments about the code Setup code Define variables Loop code Main code
  18. 18. ASE2013 Dr.Pérez 22
  19. 19. ASE2013 Dr.Pérez 23 Transistor IRF530 DC motor Diode 1N4001 Resistor Arduino Uno ARDUINO AND A DC MOTOR AND THIS SOURCE CODE
  20. 20. 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
  21. 21. ASE2013 Dr.Pérez 25 MOTOR TO IRRADIATE A SURFACE VERY SLOWLY
  22. 22. ASE2013 Dr.Pérez 26
  23. 23. ASE2013 Dr.Pérez 27 http://www.youtube.com/watch?v=UQEtOJE02wE
  24. 24. ASE2013 Dr.Pérez 28 http://www.youtube.com/watch?v=e1iUjelHC6w
  25. 25. 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
  26. 26. ASE2013 Dr.Pérez 30 LDR
  27. 27. Pulse width modulation ASE2013 Dr.Pérez 31
  28. 28. ASE2013 Dr.Pérez 32
  29. 29. ASE2013 Dr.Pérez 33 Microcontroller ATMega328 Sensors (analog inputs) Brain Sight Touch Taste Smell Hearing Muscles Nerves Wires, Circuit Heart Actuators (analog outputs)
  30. 30. 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
  31. 31. ASE2013 Dr.Pérez 35
  32. 32. ASE2013 Dr.Pérez 36
  33. 33. 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
  34. 34. 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
  35. 35. 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
  36. 36. 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
  37. 37. 41 http://www.youtube.com/watch?v=hxkYNy4zTWc
  38. 38. ASE2013 Dr.Pérez 42
  39. 39. Playing music with Arduino http://www.youtube.com/watch?v=YDL9WIVfS9w 43
  40. 40. ASE2013 Dr.Pérez 44
  41. 41. ASE2013 Dr.Pérez 45 Spychip technology?
  42. 42. 46
  43. 43. SENSORS FOR ARDUINO ASE2013 Dr.Pérez 47
  44. 44. Transistor: to amplify the signal of the sensor to the Arduino 48
  45. 45. Cloud internet of things platforms: www.cosm.com Visualize and store sensor data online www.nimbits.com www.thingspeak.com49
  46. 46. ASE2013 Dr.Pérez 50
  47. 47. 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
  48. 48. 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
  49. 49. 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

×