Animation of an electric circuit with two toggle switches and one lamp

I try to animate an electric circuit with two toggle switches and one lamp. The lamp should only illuminate when both switches are closed. I am stuck at the point where the two switches work and I can close both, but I don’t know how to control the lamp. If one of the two switches is open the lamp should turn off. I hope to find help and tipps here.
Thanks a lot.
Stefan (Germany).

Sounds like an interesting problem: I think you can solve this with timelines.

If you have two ‘masks’ covering the lighted bulb, you can have the two switches individually control two separate masks. When both are engaged, both masks will be removed. So:

  • If switch one is closed: unmask the light (timeline 1)
  • If switch two is closed: unmask the light with the second mask (timeline 2)
1 Like

Hype LogicGates

Here you go… this example uses symbols so you can reuse them and set up many examples.
It features only a simple switch but in theory complex setups could be achieved.
Only downside it uses code… BUT it illustrates the usage of independent Symbols.

View Example:
HypeLogicGates.html

Download Example:
HypeLogicGates.hype.zip

Version history:
1.0 Example with simple switches released under MIT-license
1.1 Added an example 3 with two-way connection (Wechselschaltung)
1.2 Inverted logic to isBulbOn (makes more sense), added helper isOn/isOff

4 Likes

@Stefan2537

Hi Stefan!

Here is a JavaScript solution to complement @Daniel’s timeline version…

Switches.hype.zip (20.3 KB)

Overview (please see Fig.1 below)


The two switches are given numerical values:
• “0” if switch open (-45° angle);
• “1” if switch closed (0° angle);

If the two switches are closed the total = 2 and the light goes on - if not (one of the switches is open) the light stays - or turns off.

Fig.1
Circuit

There are two functions:
One initializes variables (“setCircuitInitValue”) and the other does the work (“circuitTest”).

CircuitTest function

if (switchLeft == element) {
	switchLeftRot = hypeDocument.getElementProperty(switchLeft, 'rotateZ');
		if (switchLeftRot == -45) {
			hypeDocument.setElementProperty(switchLeft, 'rotateZ', 0, .5, 'easeinout');
        	leftCurcuit = leftCurcuit + 1;
		} else {
		hypeDocument.setElementProperty(switchLeft, 'rotateZ', -45, .5, 'easeinout');
		leftCurcuit = leftCurcuit - 1;
		} 
		//alert(leftCurcuit);
	} else if (switchRight == element) {
		switchRightRot = hypeDocument.getElementProperty(switchRight, 'rotateZ');
		if (switchRightRot == -45) {
			hypeDocument.setElementProperty(switchRight, 'rotateZ', 0, .5, 'easeinout');
        	rightCurcuit = rightCurcuit + 1;
		} else {
		hypeDocument.setElementProperty(switchRight, 'rotateZ', -45, .5, 'easeinout');
		rightCurcuit = rightCurcuit - 1;
		} 
		//alert(rightCurcuit);
	} 
	
	if (rightCurcuit + leftCurcuit == 2) {
		hypeDocument.setElementProperty(lightBulb, 'opacity', 1, 0.5, 'easeinout');
	} else { hypeDocument.setElementProperty(lightBulb, 'opacity', .25, 0.5, 'easeinout');}
1 Like

Two for one… we published at exactly the same moment. What a coincidence!

↑ look at example
Updated to version 1.1
Added an example 3 with two-way connection (Wechselschaltung)

↑ look at example
Updated to version 1.2
1.2 Inverted logic to isBulbOn (makes more sense), added helper isOn/isOff

Version 2:
Switches_JHSv2.hype.zip (20.1 KB)

• Reduced the init function “setCircuitInitValue” to (2) lines.
• Trimmed the main function “circuitTest” by more than half & spelled “circuit” correctly in the code! :roll_eyes:

The left & right switches do not need to be spec’d out individually as previously done.


circuitTest()

switchEl = hypeDocument.getElementProperty(element, 'rotateZ');	
if (switchEl == -45) {
	hypeDocument.setElementProperty(element, 'rotateZ', 0, .2, 'easeinout');
    circuitTotal = circuitTotal + 1;
} else {
	hypeDocument.setElementProperty(element, 'rotateZ', -45, .2, 'easeinout');
	circuitTotal = circuitTotal - 1;
} 	

if (circuitTotal == 2) {
	hypeDocument.setElementProperty(lightBulb, 'opacity', 1, 0.2, 'easeinout');
} else { 
  hypeDocument.setElementProperty(lightBulb, 'opacity', .25, 0.2, 'easeinout');
}
4 Likes

Thank you so much for your help. I will try to get my problem solved next weekend. I have been using hype for one week now. I hope to be successful.
Thanks again. Best wishes.
Stefan

1 Like