Switches are an important part of most electronic circuits. Switches are mechanical devices with two or more leads (or terminals) that are internally connected to metal contacts.

 

  • The simplest case, most circuits contain an on/off switch. In this lesson we will learn programming of Playme using Button.
  • Here we are using four pin tactile switch as user button.

 

  • When switch is pressed it will connect A,D metal contact to B,C and when it is released it will disconnect both metal contacts as shown below:

  • Programming with Playme: Playme consists of one switch called as user button.
  • Using this we can control or ON/OFF any device.
  • Go to mblock software and open it. Go to edit menu and select Arduino mode.

  • Playme Motor Program is a Header file for Robot programming. It makes programming simple.
  • By using this we can access all blocks easily and smoothly.
  • If we are not using this then it may give us errors in program. So put this at start of program.

  • Here we are using loop. Loop is area which will be repeated for certain times depending upon its type.
  • If we write anything inside loop then it will be repeated along with loop.
  • Forever loop means program will run continuously.
  • For example if we write a program to run motor in forward direction with forever loop then it will run until we remove power applied to it.
  •  In this we are taking one more loop i.e. if-else loop.
  • If-else loop is used to check condition.
  • Condition may be anything such as whether switch is pressed or not, whether sensor is sensing parameters or not.
  • If condition is true then and then only it will run program inside it.
  • Otherwise it will run program of else loop.

  • Put that if-else loop inside forever loop. Because we want to run this program again and again.
  • Go to Robots option and select on board button pressed block.

  • Select On board button function

  • Drag that block and place it in if loops condition block as shown in figure.

  • It will look like this.

  • Now put Left Led and Right Led block inside if loop and make both LEDs HIGH.
  • This will make LEDs ON when switch is pressed.

  • When switch is pressed then both LEDs should remain OFF for this put LOW for Left as well as Right LED inside else loop.

  • In this program we are checking whether switch is really pressed or not.
  • If it is pressed led 1 and led 2 will be ON otherwise both of them will remain OFF.
  • Now save program. Click on File menu. Select Save project.
  • Click on that. You will get this window.

 

  • Now go to connect menu. Select Serial Port option. Select your COM port number.

  • Click on Upload to Arduino option.

  • After uploading is done you will get this message.

  • Click on close option and now test your program