Blink the webcam light!

9

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.

haykam

Posted 2017-02-26T17:26:04.053

Reputation: 784

2My 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? – Doorknob – 2017-02-26T17:40:31.480

@Doorknob No, but you can provide a version that takes it into account if you'd like. – haykam – 2017-02-26T17:42:04.470

1The penalty should only be 1 byte, since you can just use .5 – Elronnd – 2017-03-01T00:46:13.343

@Elronnd I was going to add that, but I forgot. – haykam – 2017-03-01T02:10:41.633

Answers

8

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

Suever

Posted 2017-02-26T17:26:04.053

Reputation: 10 257

2The delay between each blink is more than 0.5 – haykam – 2017-02-26T23:25:23.903

2@haykam The directions (and comments) indicate that inaccuracies due to the hardware are acceptable unless I'm misreading them. – Suever – 2017-02-26T23:30:18.983

Ok... do you mind maybe adding an additional golf that does it so it looks like 0.5s? – haykam – 2017-02-26T23:31:42.510

4@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. – Suever – 2017-02-26T23:32:48.493

Last beep was good – haykam – 2017-02-27T01:52:54.093

7

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

pzp

Posted 2017-02-26T17:26:04.053

Reputation: 171

4

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.

nderscore

Posted 2017-02-26T17:26:04.053

Reputation: 4 912

@haykam thanks for the edit, but for some reason this script doesn't work inside the snippet iframe sandbox – nderscore – 2017-02-27T21:36:45.760

Ok then. I won't start an edit war. ;) – haykam – 2017-02-28T03:18:54.057

0

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

W. K.

Posted 2017-02-26T17:26:04.053

Reputation: 51

@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? – W. K. – 2018-11-19T12:05:11.857

"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. – W. K. – 2018-11-20T01:27:55.133

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. – Jonathan Frech – 2018-11-20T12:49:14.023