magni3
Published

Color Changing Buttons

Hey! Do you have a small child that wants to play with your Echo Button? This color changing button skill could keep them entertained.

IntermediateShowcase (no instructions)3 hours1,171

Things used in this project

Story

Read more

Schematics

Echo Button Diagram

Shows the process of Echo buttons

Code

GameEngine Input Handler

JavaScript
This is the Game Engine input handler. The program checks to see if the GameEngine.InputHandlerEvent is the type returned from Alexa. It receives the button press input or lack of input and responds accordingly based on the situation.
 
  switch(event.request.type) {
    
    case'System.ExceptionEncountered':
      speechOutput='You took too long to respond.  Please say change my color to start the button color change.';
      textOutput=speechOutput;
      sit=talk;
    break;
    
    
    case 'GameEngine.InputHandlerEvent':
    //Launch Request
    console.log('Game input handler');
    
    sesh=event.session.attributes;
    bstatus=event.request.events[0].name;
    switch(bstatus){
      case'complete':
        sit=start;
        p1=event.request.events[0].inputEvents[0].gadgetId;
        console.log('p1 value is'+p1);
        color=event.request.events[0].inputEvents[0].color;
        nbcount=0;
        console.log('the color before button push is '+color);
        switch(color){
          case'000000':
            color='FFFF00';
            cd='yellow';
          break;
          case'FFFF00':
            color='FF0000';
            cd='red';
          break;
          case'FF0000':
            color='00FF00';
            cd='green';
          break;
          case '00FF00':
            color='0000FF';
            cd='blue';
          break;
          case '0000FF':
            color='00FFFF';
            cd = 'turquois';
          break;
          case '00FFFF':
            color='FFFF00';
            cd='yellow';
          break;
        }
        console.log('the color after button push is '+color);
        speechOutput="<audio src='soundbank://soundlibrary/cartoon/amzn_sfx_boing_short_1x_01'/>Button has been pressed! The new color is " + cd;
        textOutput=speechOutput;
      break;
      case'failed':
        sit=start;
        nbcount=sesh.nbcount;
        nbcount=nbcount+1;
        speechOutput='No button pressed.  Warning '+ nbcount + '.  You have 60 seconds to press a button.';
        if(nbcount>1){
          sit=talk;
          ending=true;
          speechOutput= 'No button pressed.  Warning '+ nbcount+'The skill will now end.  Thanks';
        }
      break;  
    }
    
    sesh={'p1':p1,'color':color,'nbcount':nbcount};
    console.log(sesh);
    textOutput=speechOutput;
    context.succeed(          
    generateResponse(
    buildSpeechletResponse(textOutput, speechOutput, false,'Welcome',ism,ilg,bgimg,sit,sesh), 
    sesh
    )
    );
    break;

    case 'LaunchRequest':
    //Launch Request
    console.log('Actual LAUNCH REQUEST');
    color="FFFF00";
    sesh={'p1':null,'color':color,'nbcount':nbcount};
    sit=start;
    speechOutput = welcome;
    textOutput=welcome;
    context.succeed(          
    generateResponse(
    buildSpeechletResponse(textOutput, speechOutput, false,'Welcome',ism,ilg,bgimg,sit,sesh), 
    sesh
    )
    );
    break;
    //*************************
    
    

  };
  
  

Credits

magni3

magni3

2 projects • 4 followers

Comments