Arduino Nano + LCD + Joystick + Servos



Jumper setting of 0517 matrix board :

set0517_04


lcdJsServo.ino code :
#include <LiquidCrystal.h>
#include <Servo.h>

LiquidCrystal lcd(16, 17, 4,5, 6, 7); // P1
//LiquidCrystal lcd(8,9,10,11,12,13); // P2
Servo servo1; Servo servo2;

const int buttonPin = 8;
//const int buttonPin = 16;
int analogPinX = 5,analogPinY = 4;
//int analogPinX = 0,analogPinY = 1;
int buttonState = 0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.print("electronics.cat");
  pinMode(buttonPin, INPUT);
  servo1.attach(10);
  servo2.attach(11);
  servo1.write(90);
  servo2.write(90);
}

unsigned long int nAnalogValue2Degrees(unsigned long int nAnalogValue){
  return (nAnalogValue * 180) / 1023;
}

void loop() {
  buttonState = digitalRead(buttonPin);
  unsigned long int degX = nAnalogValue2Degrees(analogRead(analogPinX));
  unsigned long int degY = nAnalogValue2Degrees(analogRead(analogPinY));
  // set the cursor to column 0, line 1 (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  if (buttonState == HIGH) {
    lcd.print("F ");
  }else{
    lcd.print("N ");
  }
  lcd.print("X:");lcd.print(degX); lcd.print("d Y:");lcd.print(degY);lcd.print("d ");
  servo1.write(degX);
  servo2.write(degY);
}


Involved boards :

nano-eCat
I/O matrix
LCD adapter

ArduinoNano
LCD
Joystick

Servo