-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigiPoti.cpp
More file actions
68 lines (50 loc) · 1.04 KB
/
DigiPoti.cpp
File metadata and controls
68 lines (50 loc) · 1.04 KB
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
#include "DigiPoti.h"
#include <Arduino.h>
//#define PRINT_VAL
DigiPoti::DigiPoti(int incPin, int udPin) :
pinInc(incPin), pinUD(udPin), pos(1)
{}
void DigiPoti::setup()
{
pinMode(pinInc, OUTPUT);
pinMode(pinUD, OUTPUT);
digitalWrite(pinInc, LOW);
digitalWrite(pinUD, LOW);
// Initialize value at bottom (1)
digitalWrite(pinUD, LOW);
for(int i=0; i<150; ++i)
pulseInc();
pos = 1;
}
void DigiPoti::up()
{
if(pos >= 100)
return;
digitalWrite(pinUD, HIGH);
pulseInc();
digitalWrite(pinUD, LOW); // --> for saving power?
pos++;
#ifdef PRINT_VAL
Serial.print("poti up: ");
Serial.println(pos);
#endif
}
void DigiPoti::down()
{
if(pos <= 0)
return;
digitalWrite(pinUD, LOW);
pulseInc();
pos--;
#ifdef PRINT_VAL
Serial.print("poti down: ");
Serial.println(pos);
#endif
}
void DigiPoti::pulseInc() const
{
delayMicroseconds(12);
digitalWrite(pinInc, HIGH);
delayMicroseconds(12);
digitalWrite(pinInc, LOW);
}