-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino-MultiTool.ino
296 lines (252 loc) · 6.93 KB
/
Arduino-MultiTool.ino
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#include <LiquidCrystal.h>
/*******************************************************************************
* Kapazität Messgerät 10nF bis 2000uF und Drehzahlmesser *
*******************************************************************************/
#define messPin 1 // Analog Messeingang
#define encoderPin 2 // Induktiver Sensor-Pin
#define pulsePerRound 1 // Pulse pro Umdrehung
#define ladePin 12 // Kondensator-Lade-Pin über einen 10kOhm Widerstand
#define entladePin 13 // Kondensator-Entlade-Pin über einen 220 Ohm Widerstand
#define widerstand 9927.0F // 10 kOhm > gemessen 9,927 kOhm
/* Kondensator */
unsigned long startZeit;
unsigned long vergangeneZeit;
float microFarad;
float nanoFarad;
/* Induktiver Sensor */
unsigned int rpm;
volatile unsigned int pulses;
unsigned long timeold;
/* LCD */
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int lcd_key = 0;
int adc_key_in = 0;
/*******************************************************************************
* Die Knöpfe sind auf diese Werte zentriert: 0, 144, 329, 504, 741 *
* Wir addieren ca. 50 zu diesen Werten und prüfen, ob wir in der Nähe sind. *
*******************************************************************************/
int read_LCD_buttons() {
adc_key_in = analogRead(0);
if (adc_key_in > 1000)
{
/* Wir machen dies aus Geschwindigkeitsgründen zur ersten Option,
da es das wahrscheinlichste Ergebnis sein wird.*/
return btnNONE;
}
// V1.1 vom Velleman VMA203
/*
if (adc_key_in < 50)
{
return btnRIGHT;
}
if (adc_key_in < 250)
{
return btnUP;
}
if (adc_key_in < 450)
{
return btnDOWN;
}
if (adc_key_in < 650)
{
return btnLEFT;
}
if (adc_key_in < 850)
{
return btnSELECT;
}
*/
// V1.0 vom Velleman VMA203
if (adc_key_in < 50)
{
return btnRIGHT;
}
if (adc_key_in < 195)
{
return btnUP;
}
if (adc_key_in < 380)
{
return btnDOWN;
}
if (adc_key_in < 555)
{
return btnLEFT;
}
if (adc_key_in < 790)
{
return btnSELECT;
}
return btnNONE;
}
void read_CAP() {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Laden...");
/* Kondensator laden */
digitalWrite(ladePin, HIGH); // ladePin auf 5V, das Laden beginnt
startZeit = micros(); // Startzeit merken
while(analogRead(messPin) < 648)
{
// 647 ist 63.2% von 1023 (5V)
}
vergangeneZeit = micros() - startZeit - 114; // 0-Messung abziehen (112-116 us)
if(vergangeneZeit > 4294960000)
{
vergangeneZeit = 0; // Minuswerte auf 0 setzen (ist long, deshalb der hohe Wert)
}
/* Umrechnung: us zu Sekunden ( 10^-6 ) und Farad zu mikroFarad ( 10^6 ), netto 1 */
microFarad = ( (float)vergangeneZeit / widerstand );
Serial.print(vergangeneZeit); // Zeit ausgeben
Serial.println(" nS");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(vergangeneZeit);
lcd.print(" nS");
delay(1000);
if (microFarad > 1)
{
if(microFarad < 100)
{
Serial.print(microFarad, 2); // uF.x ausgeben
Serial.println(" uF");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(microFarad, 2);
lcd.print(" uF");
}
else
{
Serial.print( (long)microFarad ); // uF ausgeben
Serial.println(" uF");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print( (long)microFarad );
lcd.print(" uF");
}
}
else
{
nanoFarad = microFarad * 1000.0; // in nF umrechnen
if(nanoFarad > 10)
{
Serial.print( (long)nanoFarad ); // nF ausgeben
Serial.println(" nF");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print( (long)nanoFarad );
lcd.print(" nF");
}
else
{
Serial.println("kleiner 10 nF");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("kleiner 10 nF");
}
}
/* Kondensator entladen */
digitalWrite(ladePin, LOW); // ladePin auf 0V
pinMode(entladePin, OUTPUT); // entladePin wird Ausgang
digitalWrite(entladePin, LOW); // entladePin auf 0V
lcd.setCursor(0, 1);
lcd.print("Entaden...");
while(analogRead(messPin) > 0)
{
// bis der Kondensator entladen ist (0V)
}
pinMode(entladePin, INPUT); // entladePin wird Eingang
while( (micros() - startZeit) < 500000 )
{
// bis 500ms warten, d.h. max 2 Ausgaben pro Sekunde
}
lcd.setCursor(0, 1);
lcd.print(" ");
}
void count_RPM()
{
pulses++;
}
void setup_RPM()
{
lcd.clear();
lcd.print("Speed");
pinMode(encoderPin, INPUT);
attachInterrupt(digitalPinToInterrupt(encoderPin), count_RPM, RISING);
pulses = 0;
rpm = 0;
timeold = 0;
}
void loop_RPM()
{
while(true) {
if ( millis() - timeold >= 1000 ) {
detachInterrupt(digitalPinToInterrupt(encoderPin));
rpm = pulses * (60/pulsePerRound);
pulses = 0;
timeold = millis();
lcd.setCursor (0, 1);
lcd.print(rpm);
lcd.print("rpm ");
lcd.setCursor(8, 1);
attachInterrupt(digitalPinToInterrupt(encoderPin), count_RPM, RISING);
}
}
}
void setup() {
pinMode(ladePin, OUTPUT); // ladePin als Ausgang
digitalWrite(ladePin, LOW);
Serial.begin(9600);
lcd.begin(16, 2);
Serial.println("Kappa v1.0");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kappa v1.0");
}
void loop() {
lcd.setCursor(0, 1);
lcd_key = read_LCD_buttons();
switch (lcd_key)
{
case btnRIGHT:
{
lcd.print("RIGHT ");
setup_RPM();
loop_RPM();
break;
}
case btnLEFT:
{
lcd.print(adc_key_in);
lcd.print(" v ");
break;
}
case btnUP:
{
lcd.print("UP ");
break;
}
case btnDOWN:
{
lcd.print("DOWN ");
break;
}
case btnSELECT:
{
lcd.print("SELECT ");
read_CAP();
break;
}
case btnNONE:
{
lcd.print("Press SELECT ");
break;
}
}
}