/*
Servo
a potentiometer controls the position of a servo
This example is part of the Fritzing Creator Kit: www.fritzing.org/creator-kit.
*/
#include <Servo.h> // include the library Servo.h
#include "Adafruit_ILI9341.h"
#define VERT_PIN A2
#define HORZ_PIN A3
#define SEL_PIN 2
#define TFT_DC 9
#define TFT_CS 10
Servo servo1; // creates a servo object
Servo servo2; // creates a servo object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup()
{
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
servo1.attach(5); // connects a servo object to pin 9
servo2.attach(6); // connects a servo object to pin 9
tft.begin();
}
void loop()
{
int vert = analogRead(VERT_PIN);
if(vert != 0 && vert != 1023) vert = 511;
int horz = analogRead(HORZ_PIN);
if(horz != 0 && horz != 1023) horz = 511;
delay(100); // give the servo time to react
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextSize(2);
tft.setTextColor(ILI9341_RED);
tft.println("Chernyahovskiy Vlad");
tft.println("3OK2");
servo1.write(map(vert, 0, 1023, 0, 179)); // turning the servo to the angle in val
servo2.write(map(horz, 0, 1023, 0, 179)); // turning the servo to the angle in val
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0,75);
tft.println("Servo1:");
tft.drawLine(0, 137, 10, map(vert, 0, 1023, 0, 275), ILI9341_GREEN);
tft.setCursor(0,200);
tft.println("Servo2:");
tft.drawLine(0, 262, 10, map(horz, 0, 1023, 0, 525), ILI9341_GREEN);
}