Other Arduino Codes and Videos by Robojax

Arduino code to use Dual axis XY Joystick with Nokia 5110 LCD Screen

دروس آردوینو به فارسی

Arduino code Dual Axis Joystick with NOkia 5110 Screen to dipslay dot

Arduino code to use Dual axis XY Joystick with Nokia 5110 Screen to move dot on the screen

 /*
 * this is Arduino code to use Dual axis XY Joystick with Nokia 5110 Screen to move dot on the screen
 * also read the switch.
 * Other Arduino library and videos http://robojax.com/learn/arduino/
 
 * Watch the video for this code to learn it fully.
  * Watch the video here: https://youtu.be/zqDZybR5JSE
 * this code is offered "as is" without any warranty.
 * if you are sharing this code, you must keep this copyright note.
 */
 /*
/* Nokia 5100 LCD Example Code with Added Joystick by Robojax
   Graphics driver and PCD8544 interface code for SparkFun's
   84x48 Graphic LCD.
   https://www.sparkfun.com/products/10168
   Original Source code
https://github.com/sparkfun/GraphicLCD_Nokia_5110

  This stuff could all be put into a library, but we wanted to
  leave it all in one sketch to keep it as transparent as possible.

  Hardware: (Note most of these pins can be swapped)
    Graphic LCD Pin ---------- Arduino Pin
       1-VCC       ----------------  5V
       2-GND       ----------------  GND
       3-SCE       ----------------  7
       4-RST       ----------------  6
       5-D/C       ----------------  5
       6-DN(MOSI)  ----------------  11
       7-SCLK      ----------------  13
       8-LED       - 330 Ohm res --  9
   The SCLK, DN(MOSI), must remain where they are, but the other 
   pins can be swapped. The LED pin should remain a PWM-capable
   pin. Don't forget to stick a current-limiting resistor in line
   between the LCD's LED pin and Arduino pin 9!
   Modified by Ahmad S. for Robojax.com
   on Mar 11, 2018 at 20:49 at Ajax, Ontario, Canada
*/
#include <SPI.h>
#include "LCD_Functions.h"

#define sw 2 // pint 2 is used for joystick switch input
#define screenWidth 83 // NOkia screen width
#define screenHeight 47 // Nokia screen height
int thickness =1;// the thickness of the dot


void setup()
{
  // Robojax Dual Axis joystick  with Nokia 5110 LCD screen project
  Serial.begin(9600);

  lcdBegin(); // This will setup our pins, and initialize the LCD
  //updateDisplay(); // with displayMap untouched, SFE logo
  setContrast(40); // Good values range from 40-60
  delay(1000);

  clearDisplay(BLACK);
  updateDisplay();
}


void loop()
{
  clearDisplay(WHITE);  
   // Robojax Dual Axis joystick  with Nokia 5110 LCD screen project
  int x = analogRead(A0);// read the x position of joystick
  int y = analogRead(A1); // read the y position of joystick
  int xPos = map(x, 0, 1023,0,screenWidth);// map or translate the x of joystick to x of screen
  int yPos = map(y, 0, 1023,0,screenHeight); // map or translate the y of joystick to y of screen
  int sStat = digitalRead(sw);//read the switch from pin 2
  Serial.print("X: ");
  Serial.print(xPos);
  Serial.print(" Y: ");
  Serial.println(yPos);// Robojax prints y

  // Robojax Dual Axis joystick  with Nokia 5110 LCD screen project
   //setCircle(xPos, yPos, thicness, BLACK, 2);
   // xPos is the position of x
   // yPos is the position of y
   // thickness
   setCircle(xPos, yPos, thickness, BLACK, 2);// display the dot on the screen
    updateDisplay();
  delay(10);


}





   

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal