-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicroView_Thermocouple_TempGauge.ino6071914031836809733.tmp
127 lines (90 loc) · 3.45 KB
/
MicroView_Thermocouple_TempGauge.ino6071914031836809733.tmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <SwitecX25.h>
#include <MicroView.h>
#include <TimerOne.h>
//////////////////////////////////////////////////////////////////////////////////////////////////
// configurables
//////////////////////////////////////////////////////////////////////////////////////////////////
#define TEMP_RESOLUTION ((float)0.25) // °C/mv
#define TEMP_OFFSET ((float)0.0) // °C
#define TEMP_GAUGE_MIN 0 //°C
#define TEMP_GAUGE_MAX 1000 //°C
#define GAUGE_DEGREES 315
#define GAUGE_STEPS (GAUGE_DEGREES*3)
#define GAUGE_MIN 0.0
#define GAUGE_MAX 1000.0
#define GAUGE_DIR_FWD 0
#define GAUGE_DIR_REV 1
#define GAUGE_DIR GAUGE_DIR_REV
//////////////////////////////////////////////////////////////////////////////////////////////////
// variables
//////////////////////////////////////////////////////////////////////////////////////////////////
int sensorPin = A0; // pin to use for analog readings
int sensorMv = 0; // filtered voltage to use for calculations
double temperature = 0; // calcluated temperature from sensor
int motorPos = 0;
unsigned long runtime = 0;
double currentPos = 0;
double nextPos = 0;
SwitecX25 motor1( GAUGE_STEPS, 2, 3, 5, 6 );
//////////////////////////////////////////////////////////////////////////////////////////////////
// function prototypes
//////////////////////////////////////////////////////////////////////////////////////////////////
void TimerInterrupt( void );
void MicroViewDisplay_Init( void );
void MicroViewDisplay_Update( double Temperature, int Voltage );
void MicroViewDisplay_UpdateScreen( void );
void DisplayTemperature( double Temperature );
void DisplayVoltage( int Voltage );
int GetMotorPosition( double Value, double Min, double Max );
//////////////////////////////////////////////////////////////////////////////////////////////////
// main functions
//////////////////////////////////////////////////////////////////////////////////////////////////
void setup( void )
{
Timer1.initialize(1000); // interrupt every 1000us, 1ms
Timer1.attachInterrupt(TimerInterrupt);
MicroViewDisplay_Init( );
motor1.zero( );
}
void loop( )
{
// get sensor reading and convert the temperature
sensorMv = AverageSensorValue( analogRead( sensorPin ) );
temperature = (((double)sensorMv * TEMP_RESOLUTION) + TEMP_OFFSET);
// do the stepper motor shit
motor1.updateBlocking( );
// update display with new values
MicroViewDisplay_Update( temperature, sensorMv );
//motor1.update( );
}
void TimerInterrupt( void )
{
runtime++;
//if ((runtime % 25) == 0)
{
// motorPos = GetMotorPosition( temperature, GAUGE_MIN, GAUGE_MAX );
}
if ((runtime % 100) == 0)
{
MicroViewDisplay_UpdateScreen( );
motor1.setPosition( GetMotorPosition( temperature, GAUGE_MIN, GAUGE_MAX ) );
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// function implementations
//////////////////////////////////////////////////////////////////////////////////////////////////
int GetMotorPosition( double Value, double Min, double Max )
{
int out;
if (Value > Max)
Value = Max;
if (Value < Min)
Value = Min;
Value = (Value - Min) / (Max - Min);
if (GAUGE_DIR == GAUGE_DIR_REV)
{
Value = (1.0 - Value);
}
out = (int)(((double)GAUGE_STEPS * Value) + 0.5);
return out;
}