Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. int rosu=2;
  2. int buton=4;
  3. int verde=7;
  4. int senTem=A0;
  5. int galben=5;
  6. int contor=0;
  7.  
  8. void setup() {
  9. // put your setup code here, to run once:
  10. pinMode(rosu,OUTPUT);
  11. pinMode(buton,INPUT);
  12. pinMode(verde,OUTPUT);
  13. // pinMode(galben,OUTPUT);
  14. digitalWrite(rosu,HIGH);
  15. Serial.begin(9600);
  16. }
  17.  
  18. void loop() {
  19. // put your main code here, to run repeatedly:
  20. if(digitalRead(buton)==HIGH && contor==0)
  21. {
  22. digitalWrite(verde,HIGH);
  23. digitalWrite(rosu,LOW);
  24.  
  25. Serial.print("Temperatura: ");
  26. float temp=fctTemp(10,senTem);
  27. Serial.print(temp);
  28. Serial.print(" ");
  29. Serial.print(176);
  30. Serial.println("C");
  31. delay(2000);
  32. if(temp>=27 && temp<28)
  33. {
  34. analogWrite(galben,50);
  35. }
  36. if(temp>=28 && temp<29)
  37. {
  38. analogWrite(galben,150);
  39. }
  40. if(temp>=29 && temp<30)
  41. {
  42. analogWrite(galben,200);
  43. }
  44. if(temp>=30)
  45. {
  46. analogWrite(galben,250);
  47. }
  48. contor=1;
  49. delay(1000);
  50. }
  51.  
  52. if(contor==1 && digitalRead(buton)==HIGH)
  53. {
  54. digitalWrite(verde,LOW);
  55. digitalWrite(rosu,HIGH);
  56.  
  57. }
  58. }
  59.  
  60. float fctTemp(int c,int p){
  61. float tempMediata=0;
  62. float sumaTemp=0;
  63. for(int i=0;i<c;i++)
  64. {
  65. int reading=analogRead(p);
  66. float v=reading*5.0;
  67. v /=1024.0;
  68. float tempCelsius=(v -0.5)*100;
  69. sumaTemp=sumaTemp+tempCelsius;
  70. }
  71. return sumaTemp/(float)c;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement