evive Inbuilt Tactile Switches

evive Tactile Switch Pushbuttons
Description
Learn how to use the tactile switch blocks in PictoBlox to control the Arduino pins connected to the tactile switches. This tutorial will show you how to rotate a sprite if tactile switch 1 is pressed.

Introduction

The two tactile switches are connected to Arduino pins 38 and 39, both active high. This means that the pins are at +5V when the switch is pressed, and at 0V (Ground) otherwise.

evive Tactile Switch Pushbuttons

evive Notes Icon
Note that pins 38, and 39 are pulled low, i.e. they will be at 0V (and not floating) when the switch is not pressed.

Programming in Arduino IDE

The test code for the tactile switch is given below:

/*
 evive inbuilt pushbutton code

Pushbutton 1 is connected to digital pin 38.
 Pushbutton 2 is connected to digital pin 39.
 
 This code demonstrates how to use evive inbuilt tactile switches.
 The code turns on and off a light emitting diode(LED) connected to digital
 pin 13, when pressing a pushbutton.
 
 Created by Pankaj Kumar Verma and Akshat Agarwal
 On 12 Dec, 2016
 This example code is in the public domain.
 */

// set pin numbers:
int buttonPin = 38; // the number of the pushbutton 1 pin
//int buttonPin = 39; // the number of the pushbutton 2 pin

// Note: This code is meant to run for only one pushbutton. Please initialise only one of the pushbutton.

int ledPin = 13; // the number of the LED pin

int buttonState = 0; // variable for reading the pushbutton status

void setup() {
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);
 // initialize the pushbutton pin as an input:
 pinMode(buttonPin, INPUT);
 // open serial port, set data rate at 9600 bps:
 Serial.begin(9600);
}

void loop() {
 // read the state of the pushbutton value:
 buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
 // if it is, the buttonState is HIGH:
 if (buttonState == HIGH) {
 // print on serial monitor
 Serial.println("Pushbotton is Pressed");
 delay(100);
 // turn LED on:
 digitalWrite(ledPin, HIGH);
 } else {
 // turn LED off:
 digitalWrite(ledPin, LOW);
 }
}

Programming in PictoBlox

To get the state of the tactile switch, you can use tactile switch () pressed block. This block can be found under evive extension. The switch whose state you want to check can be chosen from the drop-down on this block. It is a Boolean block that returns “TRUE” if the switch is pressed and “False” if the switch is not pressed.

tactile switch pressed

Example

  • Rotating the sprite if the tactile switch 1 is pressed.

tactile switch example

Conclusion

In conclusion, this lesson showed how to use the tactile switch blocks in PictoBlox to control the Arduino pins connected to the tactile switches. The example demonstrated how to rotate a sprite if the tactile switch 1 was pressed. With this knowledge, you can now program evive to interact with the world around it by sensing the environment with tactile switches.

Table of Contents