Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <UTFTGLUE.h> //use GLUE class and constructor
- UTFTGLUE myGLCD(0, A2, A1, A3, A4, A0); //all dummy args
- float rev; // Revolution Count
- float measureTime = 0;
- int ThermistorPin1 = 15;
- int ThermistorPin2 = 14;
- int Vo;
- float R1 = 10000;
- float logR2, R2, T1, T2, Tc1, Tf1, Tc2, Tf2;
- float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
- float rpm = 0;
- void setup() {
- Serial.begin(115200);
- pinMode(2, INPUT); // Interrupt 0
- Serial.print("***TACHOMETER***");
- delay(500);
- // Setup the LCD
- myGLCD.InitLCD(3);
- myGLCD.clrScr();
- myGLCD.setColor(255, 255, 255);
- myGLCD.setBackColor(0, 0, 0);
- print_lcd_startup();
- attachInterrupt(2, addRevolution, FALLING);
- }
- void addRevolution() {
- rev++;
- }
- void loop() {
- delay(1000);
- //noInterrupts();
- if (millis() - measureTime > 1000){
- rpm = (rev / 12) * 60;
- rev = 0;
- measureTime = millis();
- }
- //rpm = rev * 7500 / (millis() - measureTime);
- //rev = 0;
- //measureTime = millis();
- read_temp();
- print_lcd();
- Serial.println(rpm);
- //interrupts();
- }
- void read_temp() {
- Vo = analogRead(ThermistorPin1);
- R2 = R1 * (1023.0 / (float)Vo - 1.0);
- logR2 = log(R2);
- T1 = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
- Tc1 = T1 - 273.15;
- Tf1 = (Tc1 * 9.0) / 5.0 + 32.0;
- Vo = analogRead(ThermistorPin2);
- R2 = R1 * (1023.0 / (float)Vo - 1.0);
- logR2 = log(R2);
- T2 = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
- Tc2 = T2 - 273.15;
- Tf2 = (Tc2 * 9.0) / 5.0 + 32.0;
- Serial.print("Temperature: ");
- Serial.print(Tf1);
- Serial.print(" F; ");
- Serial.print(Tc1);
- Serial.println(" C");
- }
- void print_lcd() {
- myGLCD.setFont(BigFont);
- if (Tc1 < 25) {
- myGLCD.setColor(0, 255, 255);
- myGLCD.print(" ", 30, 160);
- myGLCD.printNumI(Tc1, 30, 160);
- myGLCD.print("C", 90, 160);
- } else if (Tc1 > 24 && Tc1 < 100) {
- myGLCD.setColor(255, 255, 0);
- myGLCD.print(" ", 30, 160);
- myGLCD.printNumI(Tc1, 30, 160);
- myGLCD.print("C", 90, 160);
- } else if (Tc1 > 99) {
- myGLCD.setColor(255, 0, 0);
- myGLCD.print(" ", 30, 160);
- myGLCD.printNumI(Tc1, 30, 160);
- myGLCD.print("C", 90, 160);
- }
- myGLCD.setColor(255, 255, 255);
- myGLCD.print(" ", 210, 50);
- myGLCD.printNumI(rpm, 210, 50);
- myGLCD.print(" ", 220, 160);
- myGLCD.printNumI(Tc2, 220, 160);
- myGLCD.print("C", 280, 160);
- }
- void print_lcd_startup() {
- myGLCD.setFont(BigFont);
- myGLCD.setColor(0, 128, 0);
- myGLCD.print("Stirling Engine", 40, 0);
- myGLCD.print("Experiments", 70, 20);
- myGLCD.setColor(255, 255, 255);
- myGLCD.print("RPM: ", 80, 50);
- myGLCD.print("Temperatures", 60, 100);
- myGLCD.print(" Engine Ambient", 0, 130);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement