Hi everyone. I am just a beginner in Arduino and our team is planning to design an art, which use the motion to trigger the video play or pause. I will explain more in here. Basically when the man walk pass the sensors, the video will start to play. When the man stop, the video will pause, til the man man walk again and the video resume playing.
The material we preferred in this project is:
Arduino UNO R3, some PIR sensor, wires, USB cable, PC with monitor(to show the video)
I had done some research for the similar project and someone said Processing can be used in this type of project, which communicating with Arduino and the motion sensors and hacking the media player to set play or pause. Interfacing with media player
However I cannot find any resources or reference. We are asking someone to teach us how to make it well for this project.
#include <Keyboard.h>
int ledPin = 13;
int inputPin = 2;
int pirState = LOW;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT); // LED as output
pinMode(inputPin, INPUT); // Sensor as input
Serial.begin(115200);
Keyboard.begin();
}
void loop(){
val = digitalRead(inputPin);
if ( val == HIGH) {
digitalWrite(ledPin, HIGH);
Keyboard.press(0x20); //spacebar
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
Not a good coder, but try this (untested).
You still have to fill in the keyboard commands.
If you use the common PIR (with two pots), turn the "time" fully counter clockwise, and leave the sensitivity pot in the middle.
Leo..
#include <Keyboard.h>
const byte pirPin = 2;
const byte ledPin = 13;
boolean pirValue = 0;
boolean pirState = 0;
void setup() {
Keyboard.begin();
Serial.begin(115200);
pinMode(ledPin, OUTPUT); // LED output
}
void loop() {
pirValue = digitalRead(pirPin);
if (pirValue && !pirState) { // if PIR goes high and pirstate was low
digitalWrite(ledPin, HIGH); // indicator LED on
// keyboard play code here
pirState = HIGH; // so it does not play again
}
if (!pirValue && pirState) { // if PIR goes low and pirState was high
digitalWrite(ledPin, LOW); // indicator LED off
//keyboard pause code here
pirState = LOW; // so it does not pause again
}
}
You are using "Keyboard.press" while you should be using "Keyboard.write" in this case. You should use Keyboard.press when you want to press multiple keys at the same time (for example CTRL + P). For only pressing one key and releasing it, then you should use Keyboard.write.
Lennyz1988:
You are using "Keyboard.press" while you should be using "Keyboard.write" in this case. You should use Keyboard.press when you want to press multiple keys at the same time (for example CTRL + P). For only pressing one key and releasing it, then you should use Keyboard.write.