fork download
  1. /*
  2.   Temperature Sensor
  3.  */
  4.  
  5. int raw = 0; float temp = 0;
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode( A0, INPUT );
  10. }
  11.  
  12.  
  13. void loop() {
  14.  
  15. int n = 10000; double s, avg;
  16. s=0;
  17. for(int i=0; i<n; i++){
  18. raw = analogRead(A0);
  19. s+=raw; //delay(10);
  20. }
  21. avg = s/n;
  22. //temp = ( avg/1023.0 )*5.0*1000/10;
  23. temp=avg/26.9398907;
  24. Serial.print("average analogRead: "); Serial.println(int(avg));
  25. Serial.print("Temperature: "); Serial.println(temp);
  26. delay(500);
  27.  
  28. }
  29.  
  30.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void setup()’:
prog.cpp:8:5: error: ‘Serial’ was not declared in this scope
     Serial.begin(9600);
     ^~~~~~
prog.cpp:9:14: error: ‘A0’ was not declared in this scope
     pinMode( A0, INPUT );
              ^~
prog.cpp:9:18: error: ‘INPUT’ was not declared in this scope
     pinMode( A0, INPUT );
                  ^~~~~
prog.cpp:9:5: error: ‘pinMode’ was not declared in this scope
     pinMode( A0, INPUT );
     ^~~~~~~
prog.cpp: In function ‘void loop()’:
prog.cpp:18:26: error: ‘A0’ was not declared in this scope
         raw = analogRead(A0);
                          ^~
prog.cpp:18:15: error: ‘analogRead’ was not declared in this scope
         raw = analogRead(A0);
               ^~~~~~~~~~
prog.cpp:24:5: error: ‘Serial’ was not declared in this scope
     Serial.print("average analogRead: "); Serial.println(int(avg));
     ^~~~~~
prog.cpp:26:5: error: ‘delay’ was not declared in this scope
     delay(500);
     ^~~~~
stdout
Standard output is empty