Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // **********************************************************
- // Code by: Tal OFer (talofer99@hotmail.com)
- // pan and tilt SERVO with RGB light on it.
- // using DMX proejct from http://www.mathertel.de/Arduino/DMXSerial.aspx
- #include <DMXSerial.h>
- #include <Servo.h>
- // Constants for demo program
- const int RedPin = 11; // PWM output pin for Red Light.
- const int GreenPin = 6; // PWM output pin for Green Light.
- const int BluePin = 5; // PWM output pin for Blue Light.
- const int PanPin = 3; // Pan servo pin.
- const int TiltPin = 4; // Tilt servo pin.
- Servo pan_seervo;
- Servo tilt_seervo;
- // default values
- #define RedDefaultLevel 0
- #define GreenDefaultLevel 0
- #define BlueDefaultLevel 0
- #define PanDefaultLevel 90
- #define TiltDefaultLevel 90
- // CHANNLES IDS
- //#define FIRSTMACHINE
- #ifdef FIRSTMACHINE
- #define RED_CH 1
- #define GREEN_CH 2
- #define BLUE_CH 3
- #define PAN_CH 4
- #define TILT_CH 5
- #else
- #define RED_CH 6
- #define GREEN_CH 7
- #define BLUE_CH 8
- #define PAN_CH 9
- #define TILT_CH 10
- #endif
- void setup () {
- Serial.begin(9600);
- Serial.println("System started");
- DMXSerial.init(DMXReceiver);
- // set some default values
- DMXSerial.write(RED_CH, RedDefaultLevel);
- DMXSerial.write(GREEN_CH, GreenDefaultLevel);
- DMXSerial.write(BLUE_CH, BlueDefaultLevel);
- DMXSerial.write(PAN_CH, 128);
- DMXSerial.write(TILT_CH, 128);
- // enable pwm outputs
- pinMode(RedPin, OUTPUT); // sets the digital pin as output
- pinMode(GreenPin, OUTPUT);
- pinMode(BluePin, OUTPUT);
- digitalWrite(RedPin, HIGH);
- delay(500);
- digitalWrite(RedPin, LOW);
- digitalWrite(GreenPin, HIGH);
- delay(500);
- digitalWrite(GreenPin, LOW);
- digitalWrite(BluePin, HIGH);
- delay(500);
- digitalWrite(GreenPin, LOW);
- // attach servos
- pan_seervo.attach(PanPin);
- tilt_seervo.attach(TiltPin);
- pan_seervo.write(PanDefaultLevel);
- tilt_seervo.write(TiltDefaultLevel);
- }
- void loop() {
- // Calculate how long no data backet was received
- unsigned long lastPacket = DMXSerial.noDataSince();
- if (lastPacket < 5000) {
- // read recent DMX values and set pwm levels
- analogWrite(RedPin, DMXSerial.read(RED_CH));
- analogWrite(GreenPin, DMXSerial.read(GREEN_CH));
- analogWrite(BluePin, DMXSerial.read(BLUE_CH));
- pan_seervo.write(map(DMXSerial.read(PAN_CH), 0, 255, 0, 180));
- tilt_seervo.write(map(DMXSerial.read(TILT_CH), 0, 255, 0, 180));
- } else {
- // Show pure red color, when no data was received since 5 seconds or more.
- analogWrite(RedPin, RedDefaultLevel);
- analogWrite(GreenPin, GreenDefaultLevel);
- analogWrite(BluePin, BlueDefaultLevel);
- pan_seervo.write(PanDefaultLevel);
- tilt_seervo.write(TiltDefaultLevel);
- } // if
- }
- // The End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement