-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestShift.cpp
More file actions
143 lines (101 loc) · 2.81 KB
/
testShift.cpp
File metadata and controls
143 lines (101 loc) · 2.81 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
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
#include <stdlib.h>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <vector>
#include <ncurses.h>
#include <wiringPi.h>
#define DATAS_KEY 0
//Global variables = pure evil !
std::vector<int> PINS {0, 2, 3};
/*PINS:
- Datas pin
- clock pin
- latch pin
*/
std::vector<int> test(32);
int resetPins() { //All output pins at LOW level
for (unsigned int pin : PINS) {
digitalWrite(pin, LOW);
}
return EXIT_SUCCESS;
}
int sendPacket(std::vector<int> & rawDatas) {
/* PWM ratio are stored with values V between 0 and 3.
When a value V is not 0, it sets on an output, and this value is decreased.
Therefore, after V passes in the loop, the output is turned off, simulating PWM */
resetPins();
unsigned int size = rawDatas.size();
for (unsigned int i(0); i<size; i++) { //LSB First, so datas are sent from the end of the table...
if(rawDatas[size-i-1]!=0){ //If (last-i) bit != 0, sent it
digitalWrite(PINS[0], HIGH);
rawDatas[size-i-1] = rawDatas[size-i-1]-1; //Decrease the value, as explained in description of the function
}
digitalWrite(PINS[1], HIGH); //Clock up...
delayMicroseconds(1); //...delay... (1us by default)
digitalWrite(PINS[1], LOW); //...Clock down.
digitalWrite(PINS[0], LOW); //Turn off the data line
}
digitalWrite(PINS[2], HIGH); //Outputs transmission, and draw dat line !
delayMicroseconds(1);
digitalWrite(PINS[2], LOW);
return EXIT_SUCCESS;
}
int drawScreen() {
/* One frame composed of several (8) cycles of PWM */
test[0]=7; //Rows
test[1]=6;
test[2]=5;
test[3]=4;
test[4]=3;
test[5]=2;
test[6]=1;
test[7]=0;
test[8]=7; //RED
test[9]=6;
test[10]=5;
test[11]=4;
test[12]=3;
test[13]=2;
test[14]=1;
test[15]=0;
test[16]=0; //GREEN
test[17]=1;
test[18]=2;
test[19]=3;
test[20]=4;
test[21]=5;
test[22]=6;
test[23]=7;
test[24]=4; //BLUE
test[25]=1;
test[26]=4;
test[27]=1;
test[28]=4;
test[29]=1;
test[30]=4;
test[31]=1;
for (unsigned int i(0); i<8; i++){ //Draws 8 frames to allow for PWM.
sendPacket(test);
delayMicroseconds(100);
//delay(100);
}
return EXIT_SUCCESS;
}
int main(){
if (wiringPiSetup()==-1){ //INIT of wiringPi
std::cout<<"Thread initialisation failed"<<std::endl;
return EXIT_FAILURE;
}
for (unsigned int pin: PINS){ //Enables outputs
pinMode(pin, OUTPUT);
}
std::cout<<"hello"<<std::endl;
while (true){
drawScreen();
//delay(150); //60 fps <=> T=165 ms
//delay(1);
}
return EXIT_SUCCESS;
}