Advertisement
Catscradler

Artemis -> Arduino sketch

Feb 20th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. // - - - - -
  2. // DmxSerial - A hardware supported interface to DMX.
  3. // DmxSerialRecv.pde: Sample DMX application for retrieving 3 DMX values:
  4. // address 1 (yellow) -> PWM Port 9
  5. // address 2 (green) -> PWM Port 6
  6. // address 3 (blue) -> PWM Port 5
  7. // address 4 (red) -> PWM Port 4
  8. //
  9. // Copyright (c) 2011 by Matthias Hertel, http://www.mathertel.de
  10. // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
  11. // Modified for use with  Artemis Spaceship Bridge Simulator
  12. //
  13. // Documentation and samples are available at http://www.mathertel.de/Arduino
  14. // 25.07.2011 creation of the DmxSerial library.
  15. // 10.09.2011 fully control the serial hardware register
  16. //            without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
  17. // 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
  18. // 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
  19. // 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
  20. // - - - - -
  21.  
  22. #include <DMXSerial.h>
  23.  
  24. // Constants for demo program
  25.  
  26. const int YellowPin =    9;  // PWM output pin for Yellow Light.
  27. const int GreenPin =  6;  // PWM output pin for Green Light.
  28. const int BluePin =   5;  // PWM output pin for Blue Light.
  29. const int RedPin =   10;  // PWM output pin for Red Light.
  30.  
  31. #define YellowDefaultLevel   0
  32. #define GreenDefaultLevel 0
  33. #define BlueDefaultLevel  0
  34. #define RedDefaultLevel  0
  35.  
  36. void setup () {
  37.   DMXSerial.init(DMXReceiver);
  38.  
  39.   // set some default values
  40.   DMXSerial.write(1, 80);
  41.   DMXSerial.write(2, 0);
  42.   DMXSerial.write(3, 0);
  43.   DMXSerial.write(4, 0);
  44.  
  45.   // enable pwm outputs
  46.   pinMode(YellowPin,  OUTPUT); // sets the digital pin as output
  47.   pinMode(GreenPin, OUTPUT);
  48.   pinMode(BluePin,  OUTPUT);
  49.   pinMode(RedPin,   OUTPUT);
  50. }
  51.  
  52.  
  53. void loop() {
  54.   // Calculate how long no data backet was received
  55.   unsigned long lastPacket = DMXSerial.noDataSince();
  56.  
  57.   if (lastPacket < 5000) {
  58.     // read recent DMX values and set pwm levels
  59.     analogWrite(YellowPin,   DMXSerial.read(1));
  60.     analogWrite(GreenPin, DMXSerial.read(2));
  61.     analogWrite(BluePin,  DMXSerial.read(3));
  62.     analogWrite(RedPin,   DMXSerial.read(4));
  63.  
  64.   } else {
  65.     // Show pure red color, when no data was received since 5 seconds or more.
  66.     analogWrite(YellowPin,   RedDefaultLevel);
  67.     analogWrite(GreenPin, GreenDefaultLevel);
  68.     analogWrite(BluePin,  BlueDefaultLevel);
  69.     analogWrite(RedPin,  RedDefaultLevel);
  70.   } // if
  71. }
  72.  
  73. // End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement