I have a Thermocouple sensor, Button Array, Led Display and a fan.
I"v setup two Situations that I can select by bottom 1 and 2 from 5 Buttom Array
In first Scenario Fan changes Speed at 27C in second scenario at 40C. My Projects
works to a degree. I have 3 Buttoms left and I would like to use them to change
triggering temperature on the fly and not with Code
Here is the Code:
#include "max6675.h"
#include "TM1637.h"
//{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//0~9,A,b,C,d,E,F
int thermoDO = 6;
int thermoCS = 5;
int thermoCLK = 4;
#define CLK 2 //Pins for TM1637
#define DIO 3
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
TM1637 tm1637(CLK, DIO);
const int motorPin = 7; // the motor pin
const int dirPin = 8; // the motor direction change pin
volatile int inputPin = A0; // buttons array analog input
uint16_t inputValue = 0; // value read from buttons array
int lastValue = 0; //saved value
void setup() {
Serial.begin(9600); // Serial is used to print sensor readings.
tm1637.init();
tm1637.set(BRIGHT_DARKEST);
//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
pinMode(motorPin, OUTPUT);
pinMode(dirPin, OUTPUT);
int inputValue = 0;
delay(2500);
}
void loop() {
// check buttons status
inputValue = analogRead(inputPin);
if (inputValue < 100 && inputValue >= 0) inputValue = 29;
else if (inputValue < 250 && inputValue > 150) inputValue = 40;
else if (inputValue < 470 && inputValue > 370) inputValue = 251;
else if (inputValue < 670 && inputValue > 570) inputValue = 252;
else if (inputValue < 870 && inputValue > 770) inputValue = 254;
else if (inputValue <= 1023 && inputValue > 950) inputValue = 255;
if (inputValue != 255) {
lastValue = inputValue;}
Serial.println(inputValue);
Serial.println(lastValue);
int temp = thermocouple.readCelsius();
delay(500);
int digitoneT = temp / 10;
int digittwoT = temp % 10;
tm1637.display(0, digitoneT);
tm1637.display(1, digittwoT);
Serial.println(temp);
if (temp >= lastValue && temp != 0) {
analogWrite(motorPin, 255);
}
else if (temp <= lastValue && lastValue != 0)
{ analogWrite(motorPin, 100);
}
else if (lastValue == 0)
{ analogWrite(motorPin, 0);
}
else if (lastValue == 255)
{ analogWrite(motorPin, 255);
}
if (lastValue == 29) {
tm1637.display(3, 11); // put a B at the end
delay(100);
}
else if (lastValue == 40) {
tm1637.display(3, 10); // put a ABS at the end
delay(100);
}
}