Arduino (IoT): Simple Tutorial TFT Pantalla 1.8″ Parte II

Arduino Honduras Santiapps Marcio Valenzuela

Tutorial TFT 1.8″ Parte II

Leyendo analogo del joystick!

Requisitos:

  1. Computadora (mac)
  2. Arduino MEGA (u otra variante Arduino) o incluso Arduino clone, Edison, Raspberry…  Este tutorial en particular usa una Arduino MEGA.
  3. Camara JPEG
  4. TFT con joystick!
  5. Breadboard
  6. Arduino IDE (https://www.arduino.cc/en/Main/Software)

El código esta aquí:

void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

#define Neutral 0
#define Press 1
#define Up 2
#define Down 3
#define Right 4
#define Left 5

// Check the joystick position
int CheckJoystick()
{
int joystickState = analogRead(3);

if (joystickState < 50) return Left;
if (joystickState < 150) return Down;
if (joystickState < 250) return Press;
if (joystickState < 500) return Right;
if (joystickState < 650) return Up;
return Neutral;
}

void loop()
{
int joy = CheckJoystick();
switch (joy)
{
case Left:
Serial.println(“Left”);
break;
case Right:
Serial.println(“Right”);
break;
case Up:
Serial.println(“Up”);
break;
case Down:
Serial.println(“Down”);
break;
case Press:
Serial.println(“Press”);
break;
}
}

 

Cool!  Podemos mover pixeles y usar menus!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s