Maurin Donneaud

Designer d’interaction @ DataPaulette, Hackerspace textile, 19 rue Garibaldi 93100 Montreuil (Seine-Saint-Denis).

DMX/Arduino/firmware

  1. // This sketch use a DMX shield with DmxSimple librairie
  2. // A photoelectric sensor used to count people : ...
  3. // A digital display to graph people count : Serial-7-Seg from Sparkfun
  4. // maurin.box@gmail.com
  5. // DmxSimple is available from: http://code.google.com/p/tinkerit
  6. // Help and support: http://groups.google.com/group/dmxsimple
  7. // TIMER2 id used by DMXSimple
  8. #include <Stdio.h>
  9. #include <DmxSimple.h>
  10. #define sensPin        9         // people sensor input pin
  11. int sensVal = 0;                 // sensor value
  12. #define sensSwitchPin        4   // switch sensor input pin
  13. int sensSwitchVal = 0;           // sensor value
  14. long Time = 0;                     // time
  15. int debounceTime = 10;            // debounce time
  16. int peopleCount = 0;              // people count
  17. int maxPeopleCount = 5000;        // set maximum count
  18. boolean peopleCountState = true;
  19. boolean DEBUG = false;
  20. void setup(){
  21.   pinMode(sensPin, INPUT);                // set pin as INPUT
  22.   digitalWrite(sensPin, HIGH);            // turn on pullup resistor
  23.   pinMode(sensSwitchPin, INPUT);          // set pin as INPUT
  24.   digitalWrite(sensSwitchPin, HIGH);      // turn on pullup resistor
  25.   /* The most common pin for DMX output is pin 3, which DmxSimple
  26.    ** uses by default. If you need to change that, do it here. */
  27.   DmxSimple.usePin(11); // TIMER2 is pin 3 & 11
  28.   /* DMX devices typically need to receive a complete set of channels
  29.    ** even if you only need to adjust the first channel. You can
  30.    ** easily change the number of channels sent here. If you don't
  31.    ** do this, DmxSimple will set the maximum channel number to the
  32.    ** highest channel you DmxSimple.write() to. */
  33.   // DmxSimple.maxChannel(4);
  34.   Serial.begin(9600);
  35.   if(!DEBUG)displayInit();
  36.   DmxSimple.write(1, 0); // DMX cannon OFF
  37.   DmxSimple.write(2, 0); // DMX light OFF
  38. }
  39. void loop(){
  40.   sensSwitchVal = digitalRead(sensSwitchPin);   // get switch value
  41.   sensVal = digitalRead(sensPin);               // get sensor value  
  42.   if( (change(&sensVal) == true) && (sensVal==LOW) && (Time>=debounceTime) && (peopleCountState==true) ){
  43.     Time = 0;                                   // init debounceTime
  44.     peopleCount++;
  45.     if(!DEBUG) digit_print(peopleCount);        // print people count on DIGIT screen
  46.     if(DEBUG) Serial.println(peopleCount);      // print people count on serial
  47.     delay(10);
  48.   }
  49.   if( (change(&sensSwitchVal) == true) && (sensSwitchVal==LOW) && (peopleCountState==true) ){
  50.     peopleCount = 4980;                         // Set people count to 4980
  51.     if(!DEBUG) digit_print(peopleCount);        // print people count on DIGIT screen
  52.     if(DEBUG) Serial.println(peopleCount);      // print people count on serial
  53.     delay(10);
  54.   }
  55.   if( (peopleCount >= maxPeopleCount) && (peopleCountState == true) ){
  56.     Time = 0;                                   // init debounceTime  
  57.     DmxSimple.write(1, 255);                    // DMX cannon ON
  58.     DmxSimple.write(2, 255);                    // DMX light ON
  59.     delay(10);
  60.     peopleCountState = false;
  61.   }
  62.   Time++;                                       // inc debounce Time
  63.   delay(5);
  64. }
  65. ///////////////////////////////////////////////////////////////////
  66. ///////////// if input values change output is true
  67. int change(int *val){  // *pointeur
  68.   static int lastVal = 0;
  69.   if(*val != lastVal){
  70.     lastVal = *val;
  71.     delay(10);
  72.     return true;
  73.   }
  74.   else{
  75.     return false;
  76.   }
  77. }
  78. //////////// SetupDisplay
  79. void displayInit(){
  80.   Serial.print(0x76, BYTE);    // reset display
  81.   Serial.print(0x7A, BYTE);    // brightness register
  82.   Serial.print(0xC8, BYTE);    // set brightness to 200 (0 - 255)
  83.   Serial.print(0x77, BYTE);    // adress o decimal points register
  84.   Serial.print(0x00, BYTE);    // turn all decimal points OFF
  85.   // make start-up signal
  86.   for(int i=0; i<20; i++){
  87.     Serial.print(random(200), BYTE);
  88.     delay(20);
  89.     Serial.print(random(200), BYTE);
  90.     delay(20);
  91.     Serial.print(random(200), BYTE);
  92.     delay(20);
  93.   }
  94.   Serial.print(0x76, BYTE);    // reset display
  95.   delay(20);
  96. }
  97. void digit_print(int myValue){
  98.   int digPos = numdigits(myValue);
  99.   for(int i=4; i>digPos; --i){
  100.     if(!DEBUG)Serial.print(0x78, BYTE);    // display a blank digit 120
  101.     delay(10);
  102.   }
  103.   if(!DEBUG)Serial.print(myValue, DEC);
  104.   delay(10);
  105. }
  106. int numdigits(int i){
  107.   char str[20];
  108.   sprintf(str, "%d", abs(i));
  109.   return(strlen(str));
  110. }

Forum sur abonnement

Pour participer à ce forum, vous devez vous enregistrer au préalable. Merci d'indiquer ci-dessous l'identifiant personnel qui vous a été fourni. Si vous n'êtes pas enregistré, vous devez vous inscrire.

Connexions'inscriremot de passe oublié ?