source: pyramid/firmware/RGB_Panel/RGB_Panel.ino @ fd3931e

Last change on this file since fd3931e was fd3931e, checked in by Steve Castellotti <sc@…>, 7 years ago

Initial commit

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 
3 Puzzlebox - Pyramid - RBG Panel
4 
5 This firmware is designed for for Puzzlebox's RGB Panel V1.2
6 Choose Duemilanove w/ATmega328 when programming this RGB Panel.
7 This code ontrols all lights on RGB Panel, and can be updated
8 via I2C/TWI communication.
9 
10 Copyright Puzzlebox Productions, LLC (2013)
11 
12 This code is released under the GNU Pulic License (GPL) version 2
13 
14 This software 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.
17 
18 You should have received a copy of the GNU General Public
19 License along with this code; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 
22 For more information about this licence please refer to http://www.gnu.org/copyleft/gpl.html
23 
24 For more details about the product please check http://puzzlebox.info
25 
26 Original Author: Azureviolin <www.azureviolin.com>
27 
28 Last Modified 2013-07-04
29 by Steve Castellotti <sc@puzzlebox.info>
30 
31*/
32
33#include <Wire.h>
34
35int b1 = 7;
36int r1 = 5;
37int g1 = 6;
38int b2 = A2;
39int r2 = A1;
40int g2 = A0;
41int t=1;
42int displayControl=1;
43int availableBytes=0;
44
45byte RGB[12][3]={
46    {255,0,0},
47    {255,255,0},
48    {0,255,0},
49    {0,255,255},
50    {0,0,255},
51    {128,0,255},
52    {255,0,0},
53    {255,255,0},
54    {0,255,0},
55    {0,255,255},
56    {0,0,255},
57    {128,0,255},
58  };
59
60
61
62void setup()
63{
64  Wire.begin(1);                // join i2c bus with address #1
65  Wire.onReceive(receiveEvent); // register event
66  initPins();
67
68}
69
70void loop()
71{
72  scan();//scan the display
73}
74
75// function that executes whenever data is received from master
76// this function is registered as an event, see setup()
77void receiveEvent(int howMany)
78{
79  int beginPos=Wire.read();
80  availableBytes=Wire.available();
81  for(int i=beginPos; i<beginPos+availableBytes; i++)
82    RGB[i/3][i%3]=Wire.read();
83}
84
85void scan()
86{
87  for (int i = 0; i < displayControl; i++) {
88   
89    digitalWrite(8,HIGH);
90    digitalWrite(r1,RGB[0][0]);
91    digitalWrite(g1,RGB[0][1]);
92    digitalWrite(b1,RGB[0][2]);
93    digitalWrite(r2,RGB[1][0]);
94    digitalWrite(g2,RGB[1][1]);
95    digitalWrite(b2,RGB[1][2]);
96    digitalWrite(r1,LOW);
97    digitalWrite(g1,LOW);
98    digitalWrite(b1,LOW);
99    digitalWrite(r2,LOW);
100    digitalWrite(g2,LOW);
101    digitalWrite(b2,LOW);
102    digitalWrite(8,LOW);
103   
104    digitalWrite(9,HIGH);
105    digitalWrite(r1,RGB[2][0]);
106    digitalWrite(g1,RGB[2][1]);
107    digitalWrite(b1,RGB[2][2]);
108    digitalWrite(r2,RGB[3][0]);
109    digitalWrite(g2,RGB[3][1]);
110    digitalWrite(b2,RGB[3][2]);
111    digitalWrite(r1,LOW);
112    digitalWrite(g1,LOW);
113    digitalWrite(b1,LOW);
114    digitalWrite(r2,LOW);
115    digitalWrite(g2,LOW);
116    digitalWrite(b2,LOW);
117    digitalWrite(9,LOW);
118   
119    digitalWrite(10,HIGH);
120    digitalWrite(r1,RGB[4][0]);
121    digitalWrite(g1,RGB[4][1]);
122    digitalWrite(b1,RGB[4][2]);
123    digitalWrite(r2,RGB[5][0]);
124    digitalWrite(g2,RGB[5][1]);
125    digitalWrite(b2,RGB[5][2]);
126    digitalWrite(r1,LOW);
127    digitalWrite(g1,LOW);
128    digitalWrite(b1,LOW);
129    digitalWrite(r2,LOW);
130    digitalWrite(g2,LOW);
131    digitalWrite(b2,LOW);
132    digitalWrite(10,LOW);
133   
134    digitalWrite(11,HIGH);
135    digitalWrite(r1,RGB[6][0]);
136    digitalWrite(g1,RGB[6][1]);
137    digitalWrite(b1,RGB[6][2]);
138    digitalWrite(r2,RGB[7][0]);
139    digitalWrite(g2,RGB[7][1]);
140    digitalWrite(b2,RGB[7][2]);
141    digitalWrite(r1,LOW);
142    digitalWrite(g1,LOW);
143    digitalWrite(b1,LOW);
144    digitalWrite(r2,LOW);
145    digitalWrite(g2,LOW);
146    digitalWrite(b2,LOW);
147    digitalWrite(11,LOW);
148   
149    digitalWrite(12,HIGH);
150    digitalWrite(r1,RGB[8][0]);
151    digitalWrite(g1,RGB[8][1]);
152    digitalWrite(b1,RGB[8][2]);
153    digitalWrite(r2,RGB[9][0]);
154    digitalWrite(g2,RGB[9][1]);
155    digitalWrite(b2,RGB[9][2]);
156    digitalWrite(r1,LOW);
157    digitalWrite(g1,LOW);
158    digitalWrite(b1,LOW);
159    digitalWrite(r2,LOW);
160    digitalWrite(g2,LOW);
161    digitalWrite(b2,LOW);
162    digitalWrite(12,LOW);
163   
164    digitalWrite(13,HIGH);
165    digitalWrite(r1,RGB[10][0]);
166    digitalWrite(g1,RGB[10][1]);
167    digitalWrite(b1,RGB[10][2]);
168    digitalWrite(r2,RGB[11][0]);
169    digitalWrite(g2,RGB[11][1]);
170    digitalWrite(b2,RGB[11][2]);
171    digitalWrite(r1,LOW);
172    digitalWrite(g1,LOW);
173    digitalWrite(b1,LOW);
174    digitalWrite(r2,LOW);
175    digitalWrite(g2,LOW);
176    digitalWrite(b2,LOW);
177    digitalWrite(13,LOW);
178   
179    //delay(t);
180  }
181}
182
183void initPins()
184
185  pinMode(b1,OUTPUT);
186  pinMode(r1,OUTPUT);
187  pinMode(g1,OUTPUT);
188  pinMode(b2,OUTPUT);
189  pinMode(r2,OUTPUT);
190  pinMode(g2,OUTPUT);
191 
192  pinMode(8,INPUT);
193  pinMode(9,INPUT);
194  pinMode(10,INPUT);
195  pinMode(11,INPUT);
196  pinMode(12,INPUT);
197  pinMode(13,INPUT);
198 
199  digitalWrite(b1,LOW);
200  digitalWrite(r1,LOW);
201  digitalWrite(g1,LOW);
202  digitalWrite(b2,LOW);
203  digitalWrite(r2,LOW);
204  digitalWrite(g2,LOW);
205 
206  digitalWrite(8,LOW);
207  digitalWrite(9,LOW);
208  digitalWrite(10,LOW);
209  digitalWrite(11,LOW);
210  digitalWrite(12,LOW);
211  digitalWrite(13,LOW);
212}
Note: See TracBrowser for help on using the repository browser.