Stap 3: CODE
Hier is de code.
Auteur: Gaige Kerns
Author: Gaige Kerns--------------------------------------------------------------*/ #include // Arduino pins used for LCD LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { // initialize the LCD display lcd.begin(16, 2); }void loop() { float temperature = 0.0; // stores the calculated temperature int sample; // counts through ADC samples float ten_samples = 0.0; // stores sum of 10 samples // take 10 samples from the MCP9700 for (sample = 0; sample < 10; sample++) { // convert A0 value to temperature temperature = ((float)analogRead(A0) * 5.0 / 1024.0) - 0.5; temperature = temperature / 0.01; // sample every 0.1 seconds delay(100); // sum of all samples ten_samples = ten_samples + temperature; } // get the average value of 10 temperatures temperature = ten_samples / 10.0; // display the temperature on the LCD lcd.setCursor(0, 0); lcd.print(temperature); lcd.print(" deg. C "); ten_samples = 0.0; }