You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
978 B
C++
47 lines
978 B
C++
#include<Arduino.h>
|
|
|
|
// vars and pins at TCLab
|
|
const int LED = 9;
|
|
const int T1 = A0; // temperature sensor T1 input
|
|
const int T2 = A2; // temperature sensor T2 input
|
|
const int Q1 = 3; // PWM at Q1 (output)
|
|
const int Q2 = 5; // PWM at Q2 (output)
|
|
|
|
|
|
// vars and constants:
|
|
int T1Val;
|
|
int T2Val;
|
|
const int nAvg = 10; // samples per reading
|
|
const long BAUD = 115200; // Freq serial comm
|
|
const float factor = 3.3/1024*100; // 3.3V/1024
|
|
|
|
// functions
|
|
|
|
float readDeg(int channel) {
|
|
float acc = 0;
|
|
for(int i=0;i<=nAvg;i++) {
|
|
acc += analogRead(channel)*factor-50;
|
|
}
|
|
return acc/nAvg;
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
pinMode(LED, OUTPUT);
|
|
analogReference(EXTERNAL);
|
|
Serial.begin(BAUD);
|
|
delay(100);
|
|
Serial.println("Temps");
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
float t1Val = readDeg(T1);
|
|
float t2Val = readDeg(T2);
|
|
Serial.print(t1Val,4); Serial.print(',');
|
|
Serial.println(t2Val,4);
|
|
delay(250);
|
|
}
|