// Solartracker Testprogramm: Hardware-Komponenten-Test
// Simultantest Arduino UNO + AF-Motorshield v.1.0 + SaintSmart
20x4 LCD-Display
// + DS3231RTC + Longruner-Servo + Pololu-Schrittmotor + Digitalausgang 2
// M. Schulte, 28. Juni 2019
#include <AFMotor.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#define RTC_I2C_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x27, 20, 4);
RTCDateTime dt;
DS3231 clock;
Servo servo1;
AF_Stepper stepper(200, 2);
int pause = 2000;
void setup()
{
pinMode(2, OUTPUT);
pinMode(A0, INPUT);
servo1.attach(9);
servo1.write(5);
clock.begin();
lcd.init();
lcd.backlight();
lcd.clear();
stepper.setSpeed(10);
//clock.setDateTime(2019, 06, 29, 13, 16, 00); // Hier Datum und aktuelle Uhrzeit setzen
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("Solartracker Test");
lcd.setCursor(0, 1);
lcd.print("M.
Schulte Jun. 2019");
lcd.setCursor(0, 2);
lcd.print("UNO MS
RTC HALL");
lcd.setCursor(0, 3);
lcd.print("LCD
Servo Stepper");
lcd.setCursor(0, 1);
lcd.print("M.
Schulte Jun. 2019");
delay (5000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Test
Ausgang D2");
lcd.setCursor(0, 2);
lcd.print("rote LED
blinkt 5x");
delay(pause);
digitalWrite(2,
HIGH); // rote
Leuchtdiode blinkt 5x
delay(500);
digitalWrite(2, LOW);
delay(500);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(500);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(500);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(500);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(pause);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Test
DS3231 RTC Uhr");
lcd.setCursor(0, 2);
lcd.print("Time
Zone: MEZ");
delay (5000);
dt =
clock.getDateTime();
digitalWrite(2, HIGH);
delay (1000);
digitalWrite(2, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.println(clock.dateFormat("d.m.Y H:i:s ", dt));
lcd.setCursor(0, 1);
lcd.print(clock.dateFormat("F", dt));
lcd.setCursor(10, 1);
lcd.print(clock.dateFormat("l", dt));
lcd.setCursor(0, 2);
lcd.print("Jahrestag");
lcd.setCursor(10, 2);
lcd.print(clock.dateFormat("z", dt));
lcd.setCursor(0, 3);
lcd.print("Schaltjahr");
lcd.setCursor(11, 3);
lcd.print(clock.dateFormat("L", dt));
delay (pause);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Test
Pololu Stepper");
delay (pause);
lcd.clear();
digitalWrite(2, HIGH);
delay (1000);
digitalWrite(2, LOW);
lcd.setCursor(0, 0);
lcd.print("100
MICROSTEP");
lcd.setCursor(0, 1);
lcd.print("<-
FORWARD <-");
stepper.step(100,
FORWARD, MICROSTEP);
lcd.setCursor(0, 1);
lcd.print("->
BACKWARD ->");
delay (pause);
stepper.step(100,
BACKWARD, MICROSTEP);
lcd.setCursor(0, 2);
lcd.print("200
INTERLEAVING");
lcd.setCursor(0, 3);
lcd.print("<-
FORWARD <-");
stepper.step(200,
FORWARD, INTERLEAVE);
lcd.setCursor(0, 3);
lcd.print("->
BACKWARD ->");
delay (pause);
stepper.step(200,
BACKWARD, INTERLEAVE);
delay (1000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Test
Longruner-Servo");
delay (pause);
lcd.clear();
digitalWrite(2, HIGH);
delay (1000);
digitalWrite(2,
LOW);
lcd.setCursor(0, 0);
lcd.print("Elevation: 5
Grad");
servo1.write(5);
delay (pause);
lcd.setCursor(0, 1);
lcd.print("Elevation: 15 Grad");
servo1.write(15);
delay (pause);
lcd.setCursor(0, 2);
lcd.print("Elevation: 30 Grad");
servo1.write(30);
delay (pause);
lcd.setCursor(0, 3);
lcd.print("Elevation: 62 Grad");
servo1.write(62);
delay (pause);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" Test Hall-Sensor");
delay (pause);
delay(pause);
lcd.clear();
int Grad;
int sensorValue =
analogRead(A0);
if (sensorValue >= 0
&& sensorValue <= 1020) {
Grad =
map(sensorValue, 214, 724, 90, 270);
}
digitalWrite(2, HIGH);
delay (pause);
digitalWrite(2,
LOW);
lcd.setCursor(0, 1);
lcd.print("Eingang
A0 = ");
lcd.print(sensorValue);
lcd.print("
mV");
lcd.setCursor(0, 2);
lcd.print("Hall-Sensor = ");
lcd.setCursor(14, 2);
lcd.print(Grad);
lcd.write(0xDF);
delay (5000);
lcd.clear();
}