Introduction
evive has an inbuilt 5-way navigational (or Joystick), which is used to navigate in the evive menu-based system. The navigational key has 4 directions: left, right, up, and down. This information is provided by the analog pin A11.
Programming in Arduino IDE
The sample code is provided below:
/*
evive navigational key
Navigational key direction pin is connected to A11.
Navigational key pushbutton pin is connected to pin 19
This code demonstrates how to use navigational key of evive.
The code detect the direction on which the key is pressed
and displays on serial monitor.
Created by Pankaj Kumar Verma
On 12 Dec, 2016
This example code is in the public domain.
*/
int navKeyAnalog = A11; // select the analog input pin
int navKeyDigital = 19; // select the digital input pin
void setup() {
// put your setup code here, to run once:
// open serial port, set data rate at 9600 bps:
Serial.begin(9600);
// declare the Pin as INPUT:
pinMode(navKeyAnalog,INPUT);
pinMode(navKeyDigital,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// read the input
int x = analogRead(navKeyAnalog);
// if the key is pressed then the digital pin is HIGH
if (digitalRead(navKeyDigital) == HIGH)
{
Serial.println("Pressed");
}
// if the key is in up direction
if (x > 150 && x < 250) { Serial.println("UP"); } // if the key is in right direction else if (x > 400 && x < 500) { Serial.println("RIGHT"); } // if the key is in down direction else if (x > 600 && x < 700) { Serial.println("DOWN"); } // if the key is in left direction else if (x > 800 && x < 900)
{
Serial.println("LEFT");
}
delay(5);
}
The center switch is connected to the digital pin 19 inactive or high mode. This means that if the switch is pressed, then pin 19 is high, otherwise, the pin is LOW.
Programming in PictoBlox
You can get the state of evive Joystick using navigation key is in state () block. This block can be found under the Robots palette in the evive extension. This block checks if the navigation key is in one of the four particular directions. The direction for which you wish to check is your choice and can be chosen from the drop down on the block.
Example
- In this script, the sprite moves up, down, left and right according to using the navigation key.
Conclusion
In conclusion, the evive Joystick allows users to navigate the menu–based system and control the sprite in PictoBlox. The Joystick is connected to the analog pin A11 and the center switch is connected to the digital pin 19. Programming in Arduino IDE and PictoBlox allows users to control the Joystick according to the direction chosen.