Documente Academic
Documente Profesional
Documente Cultură
#include <LiquidCrystal.h>
/*
The circuit:
* LCD RS pin to digital pin D12
* LCD Enable pin to digital pin D11
* LCD D4 pin to digital pin A5
* LCD D5 pin to digital pin A4
* LCD D6 pin to digital pin A3
* LCD D7 pin to digital pin A2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K potentiometer: ends to +5V and ground and wiper to LCD VO pin (pin 3)
*/
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, A5, A4, A3, A2);
//Encoder's pins
int pinA = 3; // Connected to D3 (Rotation)
int pinB = 4; // Connected to D4 (Rotation)
int SW = 5; // Connected to D5 (Pressing)
const int sIThermoPin = A0; // the analog input pin for reading an amplified
voltage of the soldering iron's thermocouple
const int hGThermoPin = A1; // the analog input pin for reading an amplified
voltage of the heat gun's thermocouple
const int sIHeatingElementPin = 8; // the output pin for controlling the soldering
iron's heating element
const int hGFanPWMPin = 9; // the output pin for controlling the heat gun's fan
const int hGHeatingElementPin = 7; // the output pin for controlling the heat
gun's heating element
int sIEncoderPosCount = 0;
int hGEncoderPosCount = 0;
int buttonLast=HIGH;
int buttonMenuPos=0;
int pinALast;
int aVal;
boolean bCW;
int sIThermo = 0;
int outputValue = 0;
int hGThermo = 0;
void setup() {
pinMode (pinA,INPUT_PULLUP);
pinMode (pinB,INPUT_PULLUP);
pinMode (SW,INPUT_PULLUP);
pinMode (hGHeatingElementPin,OUTPUT);
pinMode (sIHeatingElementPin,OUTPUT);
/* Read Pin A
Whatever state it's in will reflect the last position
*/
pinALast = digitalRead(pinA);
Serial.begin (115200);
void loop() {
// 2 step calib:
// 1) {Xi set temperature, Yi temperature measured by an external device} :
linear fit {80,48},{100,62},{160,92},{200,123},{300,197}
// this gives us 0.672409 * x-8.56477, [1]
// 2) {Xi set temperature, Yi temperature measured by an external device} :
linear fit {100,136},{150,205},{200,268},{222,300}
// this gives us 1.33191 * x + 3.48942, [2]
// Let's substitute [1] into [2]: 3.48942 + 1.33191 * (0.672409 * x-8.56477)
and then let's simplify => finally we have (0.895588 * x -7.91808) , [3]
sIThermo = analogRead(sIThermoPin); // Reads the value from the specified analog
pin, ADC will map input voltages between 0V and 5V into integer values between 0
and 1023
sIThermo = (int) (0.895588 *sIThermo -7.91808); // use [3]
int i;
//thermostat 1
i = sIEncoderPosCount - sIThermo;
i = i > 0 ? i : 0;
int sI_out;
if (i)
sI_out = HIGH;
else
sI_out = LOW;
digitalWrite(sIHeatingElementPin,sI_out);
//thermostat 2
i = hGEncoderPosCount - hGThermo;
i = i > 0 ? i : 0;
int hG_out;
if (i)
hG_out = HIGH;
else
hG_out = LOW;
digitalWrite(hGHeatingElementPin,hG_out);
fan_pwm_value = i;
analogWrite(hGFanPWMPin,fan_pwm_value);
buttonLast = buttonStatus ;
char str[16];
Serial.print("sIenc = ");
Serial.print(sIEncoderPosCount);
Serial.print(" sIThermo = ");
Serial.print(sIThermo);
Serial.print(" sI_out = ");
Serial.print(sI_out);
Serial.print(" hG_out = ");
Serial.print(hG_out);
Serial.print(" hGenc = ");
Serial.print(hGEncoderPosCount);
Serial.print(" hGThermo = ");
Serial.print(hGThermo);
Serial.print(" fanEnc = ");
Serial.print(fanEncoderPosCount);
Serial.print(" hgFan = ");
Serial.print(fan_pwm_value);
Serial.print(" buttonMenuPos = ");
Serial.println(buttonMenuPos);
switch (buttonMenuPos)
{
case 0:
sISeparator = '*'; break;
case 1:
hGSeparator = '*'; break;
case 2:
fanSeparator = '*'; break;
}