working version, simplified demo mode only
This commit is contained in:
		@@ -17,10 +17,11 @@ let colors = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let LightAnimation = {
 | 
					let LightAnimation = {
 | 
				
			||||||
  numberOfBulbs: 3,
 | 
					  numberOfBulbs: 11,
 | 
				
			||||||
  ledPin: 4,
 | 
					  ledPin: 2,
 | 
				
			||||||
  running: false,
 | 
					  running: false,
 | 
				
			||||||
  mode: "demo",
 | 
					  mode: "demo",
 | 
				
			||||||
 | 
					  generalBrightnessDivider: 3,
 | 
				
			||||||
  colorSequence: [
 | 
					  colorSequence: [
 | 
				
			||||||
    colors.dimmedWhite,
 | 
					    colors.dimmedWhite,
 | 
				
			||||||
    colors.red,
 | 
					    colors.red,
 | 
				
			||||||
@@ -42,11 +43,13 @@ let LightAnimation = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
RPC.addHandler('HouseLightning.Start', function(args) {
 | 
					RPC.addHandler('HouseLightning.Start', function(args) {
 | 
				
			||||||
  LightAnimation.running = true;
 | 
					  LightAnimation.running = true;
 | 
				
			||||||
 | 
					  LightAnimation.mode = "run";
 | 
				
			||||||
  return {result: 'ok'};
 | 
					  return {result: 'ok'};
 | 
				
			||||||
}, null);
 | 
					}, null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RPC.addHandler('HouseLightning.Stop', function(args) {
 | 
					RPC.addHandler('HouseLightning.Stop', function(args) {
 | 
				
			||||||
  LightAnimation.running = false;
 | 
					  LightAnimation.running = true; // first we want to turn off LEDs, thus needs stop-mode
 | 
				
			||||||
 | 
					  LightAnimation.mode = "stop";
 | 
				
			||||||
  return {result: 'ok'};
 | 
					  return {result: 'ok'};
 | 
				
			||||||
}, null);
 | 
					}, null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -111,7 +114,7 @@ function runNeopixel(strip, shiftBy) {
 | 
				
			|||||||
  for (i=0; i<LightAnimation.numberOfBulbs; ++i) {
 | 
					  for (i=0; i<LightAnimation.numberOfBulbs; ++i) {
 | 
				
			||||||
    colorIndex = shiftBy % LightAnimation.colorSequence.length;
 | 
					    colorIndex = shiftBy % LightAnimation.colorSequence.length;
 | 
				
			||||||
    color = LightAnimation.colorSequence[colorIndex];
 | 
					    color = LightAnimation.colorSequence[colorIndex];
 | 
				
			||||||
    strip.setPixel(i, color.r, color.g, color.b);
 | 
					    strip.setPixel(i, color.r/LightAnimation.generalBrightnessDivider, color.g/LightAnimation.generalBrightnessDivider, color.b/LightAnimation.generalBrightnessDivider);
 | 
				
			||||||
    // print("runNeo shift =", shiftBy, ", colorIndex =", colorIndex, ", r =", color.r, ", g =", color.g, ", b =", color.b);
 | 
					    // print("runNeo shift =", shiftBy, ", colorIndex =", colorIndex, ", r =", color.r, ", g =", color.g, ", b =", color.b);
 | 
				
			||||||
    shiftBy++;
 | 
					    shiftBy++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -150,6 +153,10 @@ Timer.set(1990 /* msec */, true /* repeat */, function() {
 | 
				
			|||||||
      runNeopixel(strip, shiftAnimation);
 | 
					      runNeopixel(strip, shiftAnimation);
 | 
				
			||||||
      shiftAnimation++;
 | 
					      shiftAnimation++;
 | 
				
			||||||
      print("*** demo-mode, next shift=", shiftAnimation);
 | 
					      print("*** demo-mode, next shift=", shiftAnimation);
 | 
				
			||||||
 | 
					    } else if (LightAnimation.mode === "stop") {
 | 
				
			||||||
 | 
					      strip.clear();
 | 
				
			||||||
 | 
					      strip.show();
 | 
				
			||||||
 | 
					      LightAnimation.running = false;
 | 
				
			||||||
    } else print("*** no-ack, mode =", LightAnimation.mode);
 | 
					    } else print("*** no-ack, mode =", LightAnimation.mode);
 | 
				
			||||||
  } else print("*** stopped");
 | 
					  } else print("*** stopped");
 | 
				
			||||||
}, null);
 | 
					}, null);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user