-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMAOutputDataBus.cpp
59 lines (53 loc) · 1.06 KB
/
AMAOutputDataBus.cpp
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
#include "AMAOutputDataBus.h"
using namespace AMACar;
/*
* Default constructor
*/
AMAOutputDataBus::AMAOutputDataBus(int pinsCount, int *busPins)
{
this->busSize = (byte)pinsCount;
this->busPins = new byte[pinsCount];
for (int i = 0; i < pinsCount; ++i)
this->busPins[i] = busPins[i];
}
/*
* Set a value (bases 2, 8, 10, 16) value on databus
*/
void AMAOutputDataBus::setValue(byte value)
{
for(int i = this->busSize - 1; 0 <= i; --i)
{
digitalWrite(this->busPins[i], value & 1);
value >>= 1;
}
}
/*
* Sets all pins to LOW
*/
void AMAOutputDataBus::setAllLow()
{
setValue(LOW);
}
/*
* Sets all pins to HIGH
*/
void AMAOutputDataBus::setAllHigh()
{
setValue(HIGH);
}
/*
* Prints the state of the object on the serial monitor
*/
void AMAOutputDataBus::printState()
{
Serial.print("BusSize = ");
Serial.println(busSize);
for(byte i = 0; i < busSize; ++i)
{
Serial.print("Pin#");
Serial.print(i);
Serial.print(" = ");
Serial.println(this->busPins[i]);
}
Serial.println();
}