Advertisement
NapsterMP3

DMX to I2C - RGB LED's

Jan 30th, 2017
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. int dimmerporcent =0;
  2. int dimmer=0;
  3. int strobo=0;
  4. int r=0;
  5. int g=0;
  6. int b=0;
  7. int pan =0;
  8. int pan1 =0;
  9. boolean paninvert=0;
  10. boolean tiltinvert=0;
  11. int tilt =0;
  12. int tilt1 =0;
  13. int vel=0;
  14. boolean menu=0;
  15. boolean menudmx=1;
  16. boolean menupan=0;
  17. boolean menutilt=0;
  18.  
  19. int dmx =1;
  20.  
  21. #include <DMXSerial.h>
  22. #include <Wire.h>
  23. #include <EEPROM.h>
  24.  
  25. #include <LCD.h>
  26. #include <LiquidCrystal_I2C.h>
  27. LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified backpack
  28.  
  29.  
  30. void setup () {
  31. dmx = EEPROM.read(0);
  32. paninvert=EEPROM.read(1);
  33. tiltinvert=EEPROM.read(2);
  34. DMXSerial.init(DMXReceiver);
  35. Wire.begin();
  36.  
  37.  
  38. lcd.begin (16,2); // LCD 16 x 2
  39. lcd.setBacklightPin(3,POSITIVE);
  40. lcd.setBacklight(HIGH);
  41.  
  42.  
  43. pinMode(5,OUTPUT);//r
  44. pinMode(6,OUTPUT);//g
  45. pinMode(9,OUTPUT);//b
  46. pinMode(A0,INPUT); //botões painel original da moving
  47. //pinMode(3,OUTPUT);//linha 1
  48. //pinMode(4,OUTPUT);//linha 2
  49. //pinMode(12,INPUT);//coluna 1
  50. //pinMode(13,INPUT);//coluna 2
  51.  
  52.  
  53. lcd.clear();
  54. lcd.home (); // volta para 0,0
  55. lcd.setCursor (0,0); //preimeiro e a coluna e segundo e a linha
  56. lcd.print("Everton Moving");
  57. }
  58.  
  59.  
  60. void loop() {
  61. unsigned long lastPacket = DMXSerial.noDataSince();
  62.  
  63. if (lastPacket < 5000) {
  64. pan1=(DMXSerial.read(dmx));
  65. tilt1=(DMXSerial.read(dmx+1));
  66. r=(DMXSerial.read(dmx+2));
  67. g= (DMXSerial.read(dmx+3));
  68. b= (DMXSerial.read(dmx+4));
  69. dimmer=(DMXSerial.read(dmx+5));
  70. strobo=(DMXSerial.read(dmx+6));
  71. vel=(DMXSerial.read(dmx+7));
  72. }
  73. if (paninvert==1){ pan=map(pan1,0,255,255,0); } else{ pan=pan1; }
  74. if (tiltinvert==1){ tilt=map(tilt1,0,255,255,0); } else{ tilt=tilt1; }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. if (menu==0){
  81. Wire.beginTransmission(8);
  82. Wire.write(pan);
  83. Wire.write(tilt);
  84. Wire.write(vel);
  85. Wire.endTransmission();
  86.  
  87. dimmerporcent = map(dimmer,0,255,0,100);
  88. int stroboporcent = map(strobo,0,255,400,10);
  89. int r_final = r * dimmerporcent / 100;
  90. int g_final = g * dimmerporcent / 100;
  91. int b_final = b * dimmerporcent / 100;
  92.  
  93. if( strobo > 1 ){
  94. analogWrite(5,0);
  95. analogWrite(6,0);
  96. analogWrite(9,0);
  97.  
  98. delay(stroboporcent);
  99.  
  100. analogWrite(5,r_final);
  101. analogWrite(6,g_final);
  102. analogWrite(9,b_final);
  103.  
  104. delay (stroboporcent);
  105.  
  106. }else{
  107. analogWrite(5,r_final);
  108. analogWrite(6,g_final);
  109. analogWrite(9,b_final);
  110. }
  111. }
  112.  
  113. //if (menu==1){}
  114. //if (menu==0){lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("Everton Moving");}
  115.  
  116. //for(int i =3; i < 5 ; i++){
  117. //digitalWrite(3,LOW);
  118. //digitalWrite(4,LOW);
  119. //digitalWrite(i,HIGH);
  120. int botao = analogRead(A0);
  121. //menu
  122. if (botao>214 & botao<218 ){menu=!menu; analogWrite(5,0); analogWrite(6,0); analogWrite(9,0); delay(200);
  123. if (menu==0){lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("Everton Moving");menudmx=1; menupan=0;menutilt=0;}
  124. if (menu==1){lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("Canal DMX");lcd.home (); lcd.setCursor (11,0); lcd.print(dmx);}
  125. }
  126.  
  127.  
  128.  
  129.  
  130. //alterna menu
  131. if (botao>853 & botao<857 & menu==1){
  132. delay(200);
  133. if(menudmx==1){
  134. menupan=1;
  135. menudmx=0;
  136. menutilt=0;}else{if(menupan==1){
  137. menudmx=0;
  138. menupan=0;
  139. menutilt=1;}else{
  140. if(menutilt==1){
  141. menudmx=1;
  142. menupan=0;
  143. menutilt=0;}
  144. } }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. if (menudmx==1){
  152. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("Canal DMX");lcd.home (); lcd.setCursor (11,0); lcd.print(dmx);
  153. }
  154. if (menupan==1){
  155. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("PAN");lcd.home (); lcd.setCursor (11,0); lcd.print(paninvert);
  156. }
  157. if (menutilt==1){
  158. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("TILT");lcd.home (); lcd.setCursor (11,0); lcd.print(tiltinvert);
  159. }
  160.  
  161. }
  162.  
  163.  
  164. //botão pra cima
  165. if (botao>432 & botao<436 & menu==1){
  166. delay(150);
  167. if (menudmx==1& menu==1){
  168. dmx=dmx+1;EEPROM.write(0,dmx);
  169. if(dmx==513){dmx=1;}
  170. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("Canal DMX");lcd.home (); lcd.setCursor (11,0); lcd.print(dmx);
  171. }
  172.  
  173. if (menupan==1& menu==1){
  174. paninvert=1;
  175. EEPROM.write(1,paninvert);
  176. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("PAN");lcd.home (); lcd.setCursor (11,0); lcd.print(paninvert);
  177. }
  178. if (menutilt==1& menu==1){
  179. tiltinvert=1;
  180. EEPROM.write(2,tiltinvert);
  181. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("TILT");lcd.home (); lcd.setCursor (11,0); lcd.print(tiltinvert);
  182. }
  183. }
  184.  
  185.  
  186.  
  187.  
  188. //botão pra baixo
  189. if (botao>648 & botao<652 & menu==1){
  190. delay(150);
  191. if (menudmx==1& menu==1){
  192. dmx=dmx-1;EEPROM.write(0,dmx);
  193. if(dmx==0){dmx=512;}
  194. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("Canal DMX");lcd.home (); lcd.setCursor (11,0); lcd.print(dmx);
  195. }
  196.  
  197. if (menupan==1& menu==1){
  198. paninvert=0;
  199. EEPROM.write(1,paninvert);
  200. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("PAN");lcd.home (); lcd.setCursor (11,0); lcd.print(paninvert);
  201. }
  202. if (menutilt==1& menu==1){
  203. tiltinvert=0;
  204. EEPROM.write(2,tiltinvert);
  205. lcd.clear(); lcd.home (); lcd.setCursor (0,0); lcd.print("TILT");lcd.home (); lcd.setCursor (11,0); lcd.print(tiltinvert);
  206. }
  207.  
  208. }
  209.  
  210.  
  211. //}
  212.  
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement