9
\$\begingroup\$

This challenge is inspired by Blink the CAPS LOCK by zeppelin.

Most webcams feature a small integrated LED light, indicating if the webcam is in use, as controlled by a hardware mechanism to prevent spying.

Your task is to blink it:

  1. Turn it on.
  2. Wait for 0.5 (±0.1) seconds.
  3. Turn it off again.
  4. Wait for 0.5 (±0.1) seconds;
  5. Repeat.

Please include a GIF or video of the webcam blinking, if possible. If an answer doesn't have the GIF, please add a GIF of the program running.

Rules

  • If your language is missing a subsecond sleep command, your program may use a 1 second delay instead, at a penalty of an additional byte. (replacing .5 with 1)
    • If your language, for some reason, doesn't support .5, your penalty is 2 bytes. (replacing 0.5 with 1)
  • Your program must loop unless halted by the user.
  • Your LED can start either on or off; whichever is more beneficial can be used.
  • If your LED has a turning-off delay, then it doesn't have to be taken into account, unless if you want to provide an additional version.

Scoring

This is , which means the shortest answer in bytes wins.

\$\endgroup\$
  • 2
    \$\begingroup\$ My laptop's webcam LED takes a while (around 0.3 seconds, it seems) to turn off after the video device stops being accessed. Does this have to be taken into account? \$\endgroup\$ – Doorknob Feb 26 '17 at 17:40
  • \$\begingroup\$ @Doorknob No, but you can provide a version that takes it into account if you'd like. \$\endgroup\$ – haykam Feb 26 '17 at 17:42
  • 1
    \$\begingroup\$ The penalty should only be 1 byte, since you can just use .5 \$\endgroup\$ – Elronnd Mar 1 '17 at 0:46
  • \$\begingroup\$ @Elronnd I was going to add that, but I forgot. \$\endgroup\$ – haykam Mar 1 '17 at 2:10
8
\$\begingroup\$

MATLAB, 40 bytes

while 1;w=webcam;pause(.5);delete(w);end

Creates an infinite while loop and each time through the loop, a webcam object is initialized (turns on the webcam), the script is paused for 0.5 seconds using pause, and then the webcam object is deleted (turning the webcam off).

enter image description here

\$\endgroup\$
  • 2
    \$\begingroup\$ The delay between each blink is more than 0.5 \$\endgroup\$ – haykam Feb 26 '17 at 23:25
  • 2
    \$\begingroup\$ @haykam The directions (and comments) indicate that inaccuracies due to the hardware are acceptable unless I'm misreading them. \$\endgroup\$ – Suever Feb 26 '17 at 23:30
  • \$\begingroup\$ Ok... do you mind maybe adding an additional golf that does it so it looks like 0.5s? \$\endgroup\$ – haykam Feb 26 '17 at 23:31
  • 4
    \$\begingroup\$ @haykam It's impossible, it's a limitation of MATLAB (and maybe the hardware itself). I am already showing it being turned off and back on as fast as possible. \$\endgroup\$ – Suever Feb 26 '17 at 23:32
  • \$\begingroup\$ Last beep was good \$\endgroup\$ – haykam Feb 27 '17 at 1:52
7
\$\begingroup\$

Python, 82 bytes

(Uses OpenCV for accessing the webcam.)

import cv2,time
s=time.sleep
while 1:w=cv2.VideoCapture(0);s(.5);w.release();s(.5)

enter image description here

\$\endgroup\$
4
\$\begingroup\$

Javascript (ES6), 100 bytes

(f=_=>navigator.getUserMedia({video:1},x=>s(_=>x.getTracks()[0].stop(s(f,500)),500),s=setTimeout))()

During my testing, I saw a delay between the camera being activated and the LED turning on, so the timing may not be perfect. It also must run on an https:// page.

\$\endgroup\$
  • \$\begingroup\$ @haykam thanks for the edit, but for some reason this script doesn't work inside the snippet iframe sandbox \$\endgroup\$ – nderscore Feb 27 '17 at 21:36
  • \$\begingroup\$ Ok then. I won't start an edit war. ;) \$\endgroup\$ – haykam Feb 28 '17 at 3:18
0
\$\begingroup\$

Scratch in scratchblocks2, 61 bytes

when gf clicked
turn video[on v
wait(.5)secs
turn video[off v

Sorry about the absolutely terrible video. My LED has a slight turning-on delay, it is very faint, and the GIF is 18 MB.

gif

\$\endgroup\$
  • \$\begingroup\$ @JonathanFrech I've taken a look at some Scratch answers and they all seem to use scratchblocks2. Secondly, I was doing what the challenge required? \$\endgroup\$ – W. K. Nov 19 '18 at 12:05
  • \$\begingroup\$ "Please include a GIF or video of the webcam blinking, if possible. If an answer doesn't have the GIF, please add a GIF of the program running." I included everything else above it. \$\endgroup\$ – W. K. Nov 20 '18 at 1:27
  • \$\begingroup\$ You are right. I seldom see a Scratch answer but it appears that your answer satisfies both the current byte count consensus and challenge-specific rules. Sorry for my partially uninformed critique. \$\endgroup\$ – Jonathan Frech Nov 20 '18 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.