source: pyramid/firmware/RGB_HEX/RGB_HEX.ino @ f46f0fc

Last change on this file since f46f0fc was f46f0fc, checked in by AzureViolin <hao@…>, 7 years ago

firmware updates, and deleted obsolete files

  • Property mode set to 100644
File size: 5.6 KB
Line 
1//  Puzzlebox RGB HEX board Firmware
2//  This firmware is developed for Puzzlebox's RGB HEX
3//  Choose Duemilanove w/ATmega328 when program this RGB HEX.
4//  This code ontrols all lights on RGB HEX, and can be updated
5//  via I2C/TWI communication.
6//  Author: Azureviolin <www.azureviolin.com>
7//  Copyright (C) 2013 Puzzlebox Productions LLC
8//
9//  This program is free software: you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation, either version 2 of the License, or
12//  (at your option) any later version.
13// 
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18// 
19//  You should have received a copy of the GNU General Public License
20//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22
23#include <Wire.h>
24#define DEBUG 0
25
26int b1 = 3;
27int r1 = 5;
28int g1 = 6;
29int b2 = 9;
30int r2 = 10;
31int g2 = 11;
32
33int d1d2 = 2;
34int d3d4 = 4;
35int d5d6 = 7;
36int d7d8 = 8;
37int d9d10 = 12;
38int d11d12 = 13;
39
40int t=1;
41int displayControl=1;
42int availableBytes=0;
43
44//byte RGB[12][3]={
45//    {255,0,0},
46//    {255,255,0},
47//    {0,255,0},
48//    {0,255,255},
49//    {0,0,255},
50//    {128,0,255},
51//    {255,0,0},
52//    {255,255,0},
53//    {0,255,0},
54//    {0,255,255},
55//    {0,0,255},
56//    {128,0,255},
57//  };
58byte RGB[12][3]={
59    {255,255,255},
60    {255,255,255},
61    {255,255,255},
62    {255,255,255},
63    {255,255,255},
64    {255,255,255},
65    {255,255,255},
66    {255,255,255},
67    {255,255,255},
68    {255,255,255},
69    {255,255,255},
70    {255,255,255},
71  };
72
73
74void setup()
75{
76  #if DEBUG
77  Serial.begin(115200);
78  #endif
79  Wire.begin(1);                // join i2c bus with address #1
80  Wire.onReceive(receiveEvent); // register event
81  initPins();
82
83}
84
85void loop()
86{
87  scan();//scan the display
88}
89
90// function that executes whenever data is received from master
91// this function is registered as an event, see setup()
92void receiveEvent(int howMany)
93{
94  int beginPos=Wire.read();
95  availableBytes=Wire.available();
96  for(int i=beginPos; i<beginPos+availableBytes; i++)
97    RGB[i/3][i%3]=Wire.read();
98}
99
100#if DEBUG
101long loopStartTime;
102#endif
103
104void scan()
105{
106  for (int i = 0; i < displayControl; i++) {
107
108//    #if DEBUG   
109//    loopStartTime=micros();
110//    #endif
111   
112    digitalWrite(d1d2,HIGH);
113    analogWrite(r1,RGB[0][0]);
114    analogWrite(g1,RGB[0][1]);
115    analogWrite(b1,RGB[0][2]);
116    analogWrite(r2,RGB[1][0]);
117    analogWrite(g2,RGB[1][1]);
118    analogWrite(b2,RGB[1][2]);
119    analogWrite(r1,LOW);
120    analogWrite(g1,LOW);
121    analogWrite(b1,LOW);
122    analogWrite(r2,LOW);
123    analogWrite(g2,LOW);
124    analogWrite(b2,LOW);
125    digitalWrite(d1d2,LOW);
126   
127//    #if DEBUG
128//    Serial.print("D12:");
129//    Serial.println(micros()-loopStartTime);
130//    #endif
131   
132    digitalWrite(d3d4,HIGH);
133    analogWrite(r1,RGB[2][0]);
134    analogWrite(g1,RGB[2][1]);
135    analogWrite(b1,RGB[2][2]);
136    analogWrite(r2,RGB[3][0]);
137    analogWrite(g2,RGB[3][1]);
138    analogWrite(b2,RGB[3][2]);
139    analogWrite(r1,LOW);
140    analogWrite(g1,LOW);
141    analogWrite(b1,LOW);
142    analogWrite(r2,LOW);
143    analogWrite(g2,LOW);
144    analogWrite(b2,LOW);
145    digitalWrite(d3d4,LOW);
146   
147    digitalWrite(d5d6,HIGH);
148    analogWrite(r1,RGB[4][0]);
149    analogWrite(g1,RGB[4][1]);
150    analogWrite(b1,RGB[4][2]);
151    analogWrite(r2,RGB[5][0]);
152    analogWrite(g2,RGB[5][1]);
153    analogWrite(b2,RGB[5][2]);
154    analogWrite(r1,LOW);
155    analogWrite(g1,LOW);
156    analogWrite(b1,LOW);
157    analogWrite(r2,LOW);
158    analogWrite(g2,LOW);
159    analogWrite(b2,LOW);
160    digitalWrite(d5d6,LOW);
161   
162    digitalWrite(d7d8,HIGH);
163    analogWrite(r1,RGB[6][0]);
164    analogWrite(g1,RGB[6][1]);
165    analogWrite(b1,RGB[6][2]);
166    analogWrite(r2,RGB[7][0]);
167    analogWrite(g2,RGB[7][1]);
168    analogWrite(b2,RGB[7][2]);
169    analogWrite(r1,LOW);
170    analogWrite(g1,LOW);
171    analogWrite(b1,LOW);
172    analogWrite(r2,LOW);
173    analogWrite(g2,LOW);
174    analogWrite(b2,LOW);
175    digitalWrite(d7d8,LOW);
176   
177    digitalWrite(d9d10,HIGH);
178    analogWrite(r1,RGB[8][0]);
179    analogWrite(g1,RGB[8][1]);
180    analogWrite(b1,RGB[8][2]);
181    analogWrite(r2,RGB[9][0]);
182    analogWrite(g2,RGB[9][1]);
183    analogWrite(b2,RGB[9][2]);
184    analogWrite(r1,LOW);
185    analogWrite(g1,LOW);
186    analogWrite(b1,LOW);
187    analogWrite(r2,LOW);
188    analogWrite(g2,LOW);
189    analogWrite(b2,LOW);
190    digitalWrite(d9d10,LOW);
191   
192    digitalWrite(d11d12,HIGH);
193    analogWrite(r1,RGB[10][0]);
194    analogWrite(g1,RGB[10][1]);
195    analogWrite(b1,RGB[10][2]);
196    analogWrite(r2,RGB[11][0]);
197    analogWrite(g2,RGB[11][1]);
198    analogWrite(b2,RGB[11][2]);
199    analogWrite(r1,LOW);
200    analogWrite(g1,LOW);
201    analogWrite(b1,LOW);
202    analogWrite(r2,LOW);
203    analogWrite(g2,LOW);
204    analogWrite(b2,LOW);
205    digitalWrite(d11d12,LOW);
206   
207//    #if DEBUG
208////    Serial.print("LT:");
209//    Serial.println(micros()-loopStartTime);
210//    #endif
211    //delay(t);
212  }
213}
214
215void initPins()
216
217  pinMode(b1,OUTPUT);
218  pinMode(r1,OUTPUT);
219  pinMode(g1,OUTPUT);
220  pinMode(b2,OUTPUT);
221  pinMode(r2,OUTPUT);
222  pinMode(g2,OUTPUT);
223 
224  pinMode(d1d2,INPUT);
225  pinMode(d3d4,INPUT);
226  pinMode(d5d6,INPUT);
227  pinMode(d7d8,INPUT);
228  pinMode(d9d10,INPUT);
229  pinMode(d11d12,INPUT);
230 
231  analogWrite(b1,LOW);
232  analogWrite(r1,LOW);
233  analogWrite(g1,LOW);
234  analogWrite(b2,LOW);
235  analogWrite(r2,LOW);
236  analogWrite(g2,LOW);
237 
238  analogWrite(d1d2,LOW);
239  analogWrite(d3d4,LOW);
240  analogWrite(d5d6,LOW);
241  analogWrite(d7d8,LOW);
242  analogWrite(d9d10,LOW);
243  analogWrite(d11d12,LOW);
244}
Note: See TracBrowser for help on using the repository browser.