Debug:
LED ON = Digital pins pulled high (internal pullup) = Motion Sensed (Or Faulty PIR / Wiring)
/* PIR Motion Sensor to MIDI Trigger w timer
25/3/2017 Dargstronix
Hardware:
1x PIR Sensor (4 pins to sensor = 12v, GND, 2x alarm pins) * Could add more sensors for increased responsiveness to movement)
1x 12v 500mA PSU for PIR
PIR Alarm Pins to Teensy GND / Pin 0
1x Teensy v3.5 (5v version) - Set USB Type to MIDI + Serial * Powered by USB (mac pro)
Compiled under Arduino v 1.6.13 https://www.arduino.cc/en/Main/OldSoftwareReleases#previous
Teensyduino 1.35 https://www.pjrc.com/teensy/td_download.html
VDMX Detect MIDI on Video Layer (Default CC 11)
*/
int pirPin = 0; // Pin for PIR (Normally Closed)
int ledPin = 13; // Built in LED (default pin 13) NO Hardware PWM on Pin 13.
long counter = 0; // counter
long video = 0; // value to store state of if video should play or not.
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
unsigned long currentMillis = millis();
/* User Config */
long duration = 5000; // Time to wait before turning up idle video loop (in mS) 5000 = 5 seconds, 60000 = 60seconds
int fadetime = 20; // fade up/down time in mS ( x 128 ) = 2.5 seconds
int midich = 0; // MIDI Channel: 0 is default
int midicc = 11; // MIDI Control Channel: 11 (MIDI CC Volume) is default
void setup()
{
pinMode(pirPin, INPUT_PULLUP); // internal pullup to HIGH
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // debug
}
void loop()
{
currentMillis = millis();
int pirState = digitalRead(pirPin);
Serial.print(" pirState: "); //debug
Serial.print(pirState); //debug
if (pirState == HIGH) // If PIR triggered
{
digitalWrite(ledPin, HIGH);
if (video==1)// If video was playing, then make it not play
{
Serial.println(" *** WAS PLAYING NOW VIDEO OFF 0 "); //debug
video=0;
fadedown();
//usbMIDI.sendControlChange(11, 0, 0); // volume =11, value 0,ch0
}
Serial.print(" TRIGGERED - Artwork Active, counter reset, video off: "); //debug
counter = currentMillis; // reset counter
}
if (pirState == LOW) // If PIR isn't triggered
{
Serial.print(" No Trig "); //debug
blink(500);
}
if(currentMillis - counter > duration)
{
if (video==0) // If video wasn't playing
{
video=1;
fadeup();
Serial.println(" *** WASN't PLAYING NOW VIDEO ON 127 "); //debug
}
Serial.print(" * DURATION Exceeded - ARTWORK INACTIVE - turn up video * "); //debug
blink(50);
}
Serial.print(" Millis - counter: "); //debug
Serial.println(currentMillis - counter); //debug
while (usbMIDI.read()) { // ignore incoming messages
// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
}
} //end main loop
void fadeup()
{
for (int x = 0; x < 128; x++) { usbMIDI.sendControlChange(midicc, x, midich); // volume =11, value x, ch0 delay(fadetime); int val = x; val = map(val, 0, 128, 0, 255); analogWrite(ledPin, val); Serial.print(" val= "); //debug Serial.println(val); //debug Serial.print(" x= "); //debug Serial.println(x); //debug } } void fadedown() { for (int x = 127; x >- 1; x--)
{
usbMIDI.sendControlChange(midicc, x, midich); // volume =11, value x, ch0
delay(fadetime);
int val = x;
val = map(val, 0, 128, 0, 255);
analogWrite(ledPin, val);
Serial.print(" val= "); //debug
Serial.println(val); //debug
Serial.print(" x= "); //debug
Serial.println(x); //debug
}
}
void blink(int blinky)
{
if(currentMillis - previousMillis > blinky)
{
previousMillis = currentMillis; // save the last time you blinked the LED
if (ledState == LOW) // if the LED is off turn it on and vice-versa:
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin, ledState); // set the LED with the ledState of the variable:
}
}




