Hi, this is my code to convert a weird type of analogue multiplex to DMX using a DMX interface board on an Arduino UNO. however, it currently doesn't work. It is too slow. im pretty sure I need too as a 70 us interrupt but I am quite new to programming so I therefore do not know how to do that.
Any help adding that or just generally cleaning up my code would be appreciated.
thanks.
Moderators note : used codetags for C
Any help adding that or just generally cleaning up my code would be appreciated.
thanks.
C:
/*
[URL]http://www.arduino.cc/en/Tutorial/Fade[/URL]
*/
#include <DMXSerial.h>
const int leb = 6;
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int param = 0;
#define LebDefaultLevel 225
// the setup routine runs once when you press reset:
void setup() {
DMXSerial.init(DMXReceiver);
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
pinMode(leb, OUTPUT);
}
void loop() {
// set the brightness of pin 9:
param=1;
analogWrite(led, 255);
delayMicroseconds (140);
analogWrite(led, 0);
delayMicroseconds (420);
chanmidp1();
for (int a=0; a<16; a++){
chanloop();
chanmid();
}
}
//the loop of channel info with before pulse
void chanloop(){
for (int i=0; i<6; i++){
analogWrite(led, 255);
delayMicroseconds (70);
analogWrite(led, 0);
delayMicroseconds (70);
brightness = 0.725*(255-DMXSerial.read(param));
analogWrite(leb, brightness);
delayMicroseconds(280);
param = param + 1;
analogWrite(leb, 0);
delayMicroseconds (140);
}
}
void chanmid(){
chanmidp1();
chanmidp1();
}
void chanmidp1(){
analogWrite(led, 255);
delayMicroseconds (70);
analogWrite(led,0);
delayMicroseconds (490);
}
Last edited by a moderator: