document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /* Programa desenvolvido by Gamesh_
  2.  
  3. com base no livro Programming Interactivity
  4.  
  5. 13/01/2011
  6.  
  7. http://brasilrobotics.blogspot.com/
  8.  
  9. */
  10.  
  11. int pin = 0;
  12. int tempc= 0, tempf=0,tempk=0;
  13. int samples[8];
  14. int i;
  15. int piezoPin = 9, botao=7, val=0;
  16.  
  17. void setup(){
  18.  
  19. Serial.begin(9600);
  20. pinMode(piezoPin, OUTPUT);
  21. pinMode(botao,INPUT);
  22.  
  23. }
  24.  
  25. void loop()
  26.  
  27. {
  28.  
  29. for(i = 0; i<=7 ;i++){
  30. samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
  31. tempc = tempc + samples[i];
  32. delay(15);
  33.  
  34. }
  35.  
  36. tempc = tempc/8.0;
  37. tempf = (tempc * 9)/ 5 + 32;
  38. tempk= tempc+273;
  39. delay(10);
  40.  
  41. // testando o botão
  42. val=digitalRead(botao);
  43.  
  44. if(val==1){
  45.  
  46. //Mostrando na tela:
  47. Serial.print("TemperaturaC:");
  48. Serial.print(tempc);
  49. Serial.print("\\t");
  50. Serial.print("TemperaturaF:");
  51. Serial.print(tempf);
  52. Serial.print("\\t");
  53. Serial.print("TemperaturaK:");
  54. Serial.print(tempk);
  55. Serial.print("\\n");
  56.  
  57. // Som:
  58.  
  59. digitalWrite(piezoPin, HIGH);
  60. delayMicroseconds(600);
  61. digitalWrite(piezoPin, LOW);
  62. delayMicroseconds(600);
  63.  
  64. }
  65.  
  66. }
');