//Sample using LiquidCrystal library
#include <TelemetryKit.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#define RXPIN 12
#define TXPIN 13
long lon, lat;
unsigned long fix_age;
TinyGPS gps;
SoftwareSerial nss(RXPIN, TXPIN);
void telemetryKitCallback(char *packet, size_t length) { }
void setup()
{
nss.begin(9600);
Serial.begin(9600);
TelemetryKitInit();
}
void loop()
{
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (nss.available())
{
char c = nss.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
long lat, lon;
unsigned long age;
gps.get_position(&lat, &lon, &age);
/*
länge der int's herausfinden
Das GPS gibt eine Zhal bis 8 stellen hinter dem Komma an, als int haben die Koordinaten natürlich kein Komma
*/
int latlen = 0;
if(lat > 10000*10000)
latlen = 10;
else if(lat > 100000*10000)
latlen = 11;
else
latlen = 9;
int lonlen = 0;
if(lon > 10000*10000)
lonlen = 10;
else if(lat > 100000*10000)
lonlen = 11;
else if(lat > 100000*100000)
lonlen = 12;
else
lonlen = 9;
int msglen;
char msg[] = lonlen,latlen,lon,lat;
TelemetryKitTransmit(msg, sizeof(msg));
}
}
/*
TelemtryKit can be found here: https://github.com/markqvist/TelemetryKit
*/
// configurable part:
#define RXPIN 12 //pin on wich Arduino recieve stuff from GPS
#define TXPIN 13 //pin on wich the Arduino transmit stuff to the GPS
#define spe 9600 //speed of your GPS
//Do not touch anything under this line
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <TelemetryKit.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>
int alt;
long lon, lat;
unsigned long fix_age, time, date, age, chars;
TinyGPS gps;
SoftwareSerial nss(RXPIN, TXPIN);
void telemetryKitCallback(char *packet, size_t length) { }
void setup()
{
nss.begin(spe);
Serial.begin(9600);
TelemetryKitInit();
}
void loop()
{
bool newData = false;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (nss.available())
{
char c = nss.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
gps.get_position(&lat, &lon, &age);
alt = gps.altitude();
gps.get_datetime(&date, &time, &age);
char buffer[13];
buffer[0] = lat >> 24;
buffer[1] = lat >> 16;
buffer[2] = lat >> 8;
buffer[3] = lat;
buffer[4] = lon >> 24;
buffer[5] = lon >> 16;
buffer[6] = lon >> 8;
buffer[7] = lon;
buffer[8] = alt >> 8;
buffer[9] = alt;
buffer[10] = time >> 24;
buffer[11] = time >> 16;
buffer[12] = time >> 8;
buffer[13] = time;
TelemetryKitTransmit(buffer, 14);
}
}
/**************************************************************************************/
/*************** Motor Pin order ********************/
/**************************************************************************************/
uint8_t PWM_PIN[2] = {9,10}; // arduino pins 9 + 10
uint16_t servo[2] = { 1500, 1500 }; // servo pulse in usec
/**************************************************************************************/
/*************** Writes the Servos values to the needed format ********************/
/**************************************************************************************/
void writeServos()
{
OCR1A = servo[0]<<1; // pin 9
OCR1B = servo[1]<<1; // pin 10
}
/**************************************************************************************/
/************ Initialize the PWM Timers and Registers ******************/
/**************************************************************************************/
void initOutput() {
/**************** mark all PWM pins as Output ******************/
for(uint8_t i=0;i<2;i++) pinMode(PWM_PIN[i],OUTPUT);
/******** Specific PWM Timers & Registers for the atmega328P (Promini) ************/
TCCR1A = (1<<WGM11) ; // 16 bit fast pwm
TCCR1B = (1<<CS11) | (1<<WGM13) | (1<<WGM12); // clk/256
ICR1 = 0x9FE0; // 20ms repetition rate
TCCR1A |= _BV(COM1A1); // connect pin 9 to timer 1 channel A
TCCR1A |= _BV(COM1B1); // connect pin 10 to timer 1 channel B
writeServos();
}
void setup()
{
initOutput();
}
void loop ()
{
//whatever ...
writeServos();
}
//Bestimmen der Grad zum drehen
pangrad = atan((groundposlat-airposlat)/(groundposlong-airposlong));
tiltgrad = atan((airposalt-groundposalt)/(sqrt((groundposlat-airposlat)*(groundposlat-airposlat)+(groundposlong-airposlong)*(groundposlong-airposlong))));
// Winkelkorrektion
//gegen den uhrzeigersinn negative winkel, mit, positiv
if ((airposlat < groundposlat) && (airposlong < groundposlong))
{
pangrad = (pangrad + 90);
}
if ((airposlat > groundposlat) && (airposlong < groundposlong))
{
pangrad = 90 - (pangrad *(-1));
}
if ((airposlat > groundposlat) && (airposlong > groundposlong))
{
pangrad = (90 - pangrad) *(-1);
}
if ((airposlat < groundposlat) && (airposlong > groundposlong))
{
pangrad = (pangrad*(-1) + 90)*(-1);
}
/*-----( Import needed libraries )-----*/
#include <Wire.h> // comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
/*-----( Declare Variables )-----*/
int sekunde, sensorValue, counter;
int c = 0;
float voltage, voltkons;
int K1 = 2;
int K2 = 3;
int K3 = 4;
long homelon, homelat, homeald, airlon, airlat, airald, TimeSetZero;
int K1read,K2read,K3read; // the current reading from the input pin
int K1previous = LOW; // the previous reading from the input pin
int K2previous = LOW;
int K3previous = LOW;
void setup() /*----( SETUP: RUNS ONCE )----*/
{
lcd.begin(20,4); // initialize the lcd for 20 chars 4 lines
lcd.setCursor(4,0);
lcd.print("DIY-Tracker");
lcd.setCursor(5,1);
lcd.print("AudioArdu");
lcd.setCursor(6,2);
lcd.print("00:00:00");
lcd.setCursor(7,3);
lcd.print("00,00V");
voltkons = (5/1023);
pinMode(K1,INPUT);
pinMode(K2,INPUT);
pinMode(K3,INPUT);
counter = 0;
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
//++++++++++++++++++++++++++++++++++++++++++++++++++
// flight time display **finished
//++++++++++++++++++++++++++++++++++++++++++++++++++
sekunde = ((millis()/1000-60*c-TimeSetZero));
if (sekunde < 10)
{
if (counter == 0) {
lcd.setCursor(13,2);
lcd.print((sekunde));
lcd.setCursor(12,2);
lcd.print("0");
}
}
else
{
if (counter == 0) {
lcd.setCursor(12,2);
lcd.print((sekunde));
}
}
switch (sekunde)
{
case 60:
c = c+1;
if (counter == 0) {
if (c = 60) {
c = 0;
}
}
if (c < 10)
{
if (counter == 0) {
lcd.setCursor(10,2);
lcd.print(c);
}
}
else
{
if (counter == 0) {
lcd.setCursor(9,2);
lcd.print(c);
}
}
break;
}
switch (c)
{
case 60:
if ((c/60) < 10)
{
if (counter == 0) {
lcd.setCursor(7,2);
lcd.print((c/60));
}
}
else
{
if (counter == 0) {
lcd.setCursor(4,1);
lcd.print((c/60));
}
}
break;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++
// voltage reading and displaying **working atm
//++++++++++++++++++++++++++++++++++++++++++++++++++
sensorValue = analogRead(A3);
float voltage = sensorValue * (5.0 / 1023.0);
// if (counter == 0) {
// lcd.setCursor(7,3);
// lcd.print(voltage);
//}
//++++++++++++++++++++++++++++++++++++++++++++++++++
// menu **testing
//++++++++++++++++++++++++++++++++++++++++++++++++++
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
K1read = digitalRead(K1);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (K1read == HIGH && K1previous == LOW && millis() - time > debounce) {
lcd.setCursor(4,0);
lcd.print("DIY--Tracker");
lcd.setCursor(5,1);
lcd.print("AudioArdu");
counter = 0;
}
K1previous = K1read;
K2read = digitalRead(K2);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (K2read == HIGH && K2previous == LOW && millis() - time > debounce) {
counter++;
if (counter > 3) {
counter = 1;
}
if (counter == 1) {
lcd.setCursor(0,1);
lcd.print("#set Home Position");
lcd.setCursor(1,4);
lcd.print("F-Zeit=>0");
lcd.setCursor(2,8);
lcd.print("SOS");
}
if (counter == 2) {
lcd.setCursor(0,1);
lcd.print("set Home Position");
lcd.setCursor(1,4);
lcd.print("#F-Zeit=>0");
lcd.setCursor(2,8);
lcd.print("SOS");
}
if (counter == 3) {
lcd.setCursor(0,1);
lcd.print("set Home Position");
lcd.setCursor(1,4);
lcd.print("F-Zeit=>0");
lcd.setCursor(2,7);
lcd.print("#SOS");
}
time = millis();
}
K2previous = K2read;
K3read = digitalRead(K3);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (K3read == HIGH && K3previous == LOW && millis() - time > debounce) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("set Home Position");
lcd.setCursor(1,4);
lcd.print("F-Zeit=>0");
lcd.setCursor(2,8);
lcd.print("SOS");
time = millis();
}
if (K3read == HIGH && K3previous == LOW && millis() - time > debounce) {
if (counter == 1) {
if (homelon != 0) {
lcd.clear();
lcd.setCursor(0,3);
lcd.print("wirklich neue");
lcd.setCursor(1,2);
lcd.print("Position setzen?");
}
else {
homelon = airlon;
homelat = airlat;
homeald = airald;
}
}
if (counter == 2) {
TimeSetZero = millis();
c = 0;
counter = 0;
}
if (counter == 3) {
lcd.setCursor(0,0);
lcd.print("Position:");
lcd.setCursor(1,0);
lcd.print(airlon);
lcd.setCursor(2,0);
lcd.print(airlat);
lcd.setCursor(3,0);
lcd.print(airald);
}
}
time = millis();
K3previous = K3read;
if (K3read == HIGH && K3previous == LOW && millis() - time > debounce && (counter==1)) {
homelon = airlon;
homelat = airlat;
homeald = airald;
counter = 0;
}
}