-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLEDs.cpp
More file actions
97 lines (84 loc) · 1.6 KB
/
LEDs.cpp
File metadata and controls
97 lines (84 loc) · 1.6 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
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
/*
* FILE: LEDs.cpp
* PROGRAM: rover
* PURPOSE: controls for LED status lights hooked up to a 74HC590, wiring not provided
* AUTHOR: Geoffrey Card
* DATE: 2014-06-09
* NOTES:
*/
#include "LEDs.h"
LEDs::LEDs(int clk_pin, int rs_pin)
{
// initalize values
_rs_pin = rs_pin;
_clk_pin = clk_pin;
_count = 0;
}
void LEDs::init(void)
{
// setup pins
pinMode(_rs_pin, OUTPUT);
pinMode(_clk_pin, OUTPUT);
// initial conditions
digitalWrite(_rs_pin, HIGH);
digitalWrite(_clk_pin, LOW);
// ensure zeroed
reset();
}
LEDs::~LEDs(void)
{
reset();
}
int LEDs::get(void)
{
return _count;
}
void LEDs::set(int count)
{
// reset and count up
reset();
if (0 < count && count < 256) {
for (int i = 0; i < count; i++) {
increment();
}
}
_count = count;
}
void LEDs::reset(void)
{
// rs -|_____|-
// clk ___|-|___
digitalWrite(_rs_pin, LOW);
delay(COUNTER_DELAY);
digitalWrite(_clk_pin, HIGH);
delay(COUNTER_DELAY);
digitalWrite(_clk_pin, LOW);
delay(COUNTER_DELAY);
digitalWrite(_rs_pin, HIGH);
delay(COUNTER_DELAY);
_count = 0;
}
void LEDs::increment(void)
{
// rs -----
// clk _|-|_
digitalWrite(_clk_pin, HIGH);
delay(COUNTER_DELAY);
digitalWrite(_clk_pin, LOW);
delay(COUNTER_DELAY);
_count++;
}
void LEDs::decrement(void)
{
// ...yeah, this is only an up counter
// down counters cost extra
set(_count-1);
}
void LEDs::test(void)
{
for (int i = 0; i < 256; i++) {
set(i);
delay(TEST_DELAY);
}
reset();
}