-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_teknik_projekt_ardunio.c++
197 lines (184 loc) · 5.08 KB
/
test_teknik_projekt_ardunio.c++
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
//Required libaries:
#include <Wire.h>
int red_light_pin= 7;// Sets which of the outputs the led strip is connected to
int green_light_pin = 8;
int blue_light_pin = 9;
int red = 255; // Turns the led strips off, 0 is on and 255 is off for each color
int blue = 255;
int green = 255;
int arrayy[1];
boolean go = false;
int old_value = 0;
int old_color[3];
int new_color[3];
void setup() { //Starts the setup function
Wire.begin(0x8); //Deffine which SMBus channel which is being used
Wire.onReceive(receiveEvent); // Activate a mode if data is being recived
Serial.begin(9600);// Starts Serial
pinMode(red_light_pin, OUTPUT);// Deffine the pins as outputs
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
arrayy[0] = 0;
}
// Function that executes whenever data is received from master
void receiveEvent(int howMany) {
while (Wire.available()) { // loop through all but the last
go = true;
arrayy[0] = Wire.read();}} // Takes the data from the raspberry pi and put it in as a veriable
void loop(){// This is the part that loops. The begning of the codes include a part of code which makes a slow transition of colors.
if (arrayy[0] == 1 && go == true){//This checks part checks the code what the input from raspberry pi is.
red = 102;
blue = 0;
green = 0;}
if(arrayy[0] == 2 && go == true){
red = 103;
blue = 0;
green = 0;}
if(arrayy[0] == 3 && go == true){
red = 51;
blue = 0;
green = 0;}
if (arrayy[0] == 4 && go == true){
red = 51;
blue = 51;
green = 0;}
if (arrayy[0] == 5 && go == true){
red = 51;
blue = 51;
green = 0;}
if (arrayy[0] == 6 && go == true){
red = 51;
blue = 26;
green = 0;}
if (arrayy[0] == 7 && go == true){
red = 51;
blue = 102;
green = 0;}
if (arrayy[0] == 8 && go == true){
red = 51;
blue = 102;
green = 0;}
if (arrayy[0] == 9 && go == true){
red = 26;
blue = 51;
green = 0;}
if (arrayy[0] == 10 && go == true){
red = 0;
blue = 153;
green = 77;}
if (arrayy[0] == 11 && go == true){
red = 0;
blue = 153;
green = 77;}
if (arrayy[0] == 12 && go == true){
red = 0;
blue = 153;
green = 77;}
if (arrayy[0] == 13 && go == true){
red = 0;
blue = 204;
green = 102;}
if (arrayy[0] == 14 && go == true){
red = 0;
blue = 204;
green = 102;}
if (arrayy[0] == 15 && go == true){
red = 0;
blue = 204;
green = 102;}
if (arrayy[0] == 16 && go == true){
red = 153;
blue = 0;
green = 77;}
if (arrayy[0] == 17 && go == true){
red = 153;
blue = 0;
green = 77;}
if (arrayy[0] == 18 && go == true){
red = 255;
blue = 102;
green = 255;}
if (arrayy[0] == 19 && go == true){
red = 153;
blue = 0;
green = 77;}
if (arrayy[0] == 20 && go == true){
red = 153;
blue = 0;
green = 77;}
if (arrayy[0] == 21 && go == true){
red = 255;
blue = 102;
green = 255;}
if (arrayy[0] == 22 && go == true){
red = 153;
blue = 0;
green = 76;}
if (arrayy[0] == 23 && go == true){
red = 204;
blue = 0;
green = 102;}
if (arrayy[0] == 24 && go == true){
red = 255;
blue = 0;
green = 127;}
if (arrayy[0] == 25 && go == true){
red = 255;
blue = 51;
green = 51;}
if (arrayy[0] == 26 && go == true){
red = 255;
blue = 51;
green = 51;}
if (arrayy[0] == 27 && go == true){
red = 255;
blue = 102;
green = 102;}
if (arrayy[0] == 28 && go == true){
red = 235;
blue = 166;
green = 27;}
if (arrayy[0] == 29 && go == true){
red = 235;
blue = 166;
green = 27;}
if (arrayy[0] == 30 && go == true){
red = 216;
blue = 165;
green = 62;}
if (arrayy[0] == 31 && go == true){
red = 73;
blue = 11;
green = 0;}
if (arrayy[0] == 32 && go == true){
red = 73;
blue = 11;
green = 0;}
if (arrayy[0] == 33 && go == true){
red = 35;
blue = 16;
green = 12;}
if (arrayy[0] == 34 && go == true){
red = 41;
blue = 0;
green = 17;}
if (arrayy[0] == 35 && go == true){
red = 41;
blue = 0;
green = 17;}
if (arrayy[0] == 36 && go == true){
red = 0;
blue = 0;
green = 0;}
old_color[0] = red;//This part transfer the information to an array
old_color[1] = blue;
old_color[2] = green;
RGB_color(old_color[0],old_color[1],old_color[2]); // This print the code to the an array
delay(100);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value){// This part prints to the outputs from the ardiuno.
if (go == true){
Serial.print(red_light_value);
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);}}