Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This code uses VK LCD Shield with a LCD and buzzer to generate the morse code numbers for the number
- of satellites being tracked ...
- Most of the codes are from tinyGPSplus and morse code Arduino examples
- I change to use PWM / analogWrite for a better sounding morse code tone ...
- Stanley Seow
- */
- #include <TinyGPS++BD.h>
- //#include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- // Morse Code timing
- #define dotPeriod 70
- #define dashPeriod (dotPeriod*3)
- #define relaxTime (dotPeriod)
- #define letterSpace (dotPeriod*2)
- #define wordSpace (dotPeriod*4)
- #define buzz 700
- #define tonePin 6
- // Buzzer = D6
- // Push button = A3
- // A3 < 50 - Right
- // A3 < 600 - Left
- // A3 < 1020 - Down
- unsigned int counter = 0;
- static const int RXPin = 7, TXPin = 8;
- static const uint32_t GPSBaud = 9600;
- // The TinyGPS++ object
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- SoftwareSerial ss(RXPin, TXPin);
- void setup()
- {
- lcd.begin(16,2);
- pinMode(tonePin,OUTPUT);
- Serial.begin(115200);
- ss.begin(GPSBaud);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Sat Monitor");
- lcd.setCursor(0,1);
- lcd.print("9W2SVT");
- playLetter(9);
- delay(letterSpace);
- playLetter('W');
- delay(letterSpace);
- playLetter(2);
- delay(letterSpace);
- playLetter('S');
- delay(letterSpace);
- playLetter('V');
- delay(letterSpace);
- playLetter('T');
- delay(letterSpace);
- delay(1000);
- }
- void loop()
- {
- static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(convertDegMin(gps.location.lat()),2);
- lcd.print(" ");
- lcd.print(gps.satellites.value());
- lcd.print(" ");
- lcd.print(gps.hdop.value());
- lcd.setCursor(0, 1);
- lcd.print(convertDegMin(gps.location.lng()),2);
- lcd.print(" ");
- lcd.print(gps.speed.kmph(),0);
- lcd.print(" ");
- lcd.print(gps.altitude.meters(),0);
- // Extract GPS value and play morse code (2 digits );
- byte n1 = gps.satellites.value()/10;
- byte n2 = gps.satellites.value() % 10;
- if ( counter % 30 == 0 ) {
- if ( n1 != 0 ) {
- playLetter(n1);
- delay(letterSpace);
- }
- playLetter(n2);
- delay(letterSpace);
- }
- counter++;
- smartDelay(1000);
- if (millis() > 5000 && gps.charsProcessed() < 10)
- Serial.println(F("No GPS data received: check wiring"));
- }
- float convertDegMin(float decDeg) {
- float DegMin;
- int intDeg = decDeg;
- decDeg -= intDeg;
- decDeg *= 60;
- DegMin = ( intDeg*100 ) + decDeg;
- return DegMin;
- }
- // This custom version of delay() ensures that the gps object
- // is being "fed".
- static void smartDelay(unsigned long ms)
- {
- unsigned long start = millis();
- do
- {
- while (ss.available())
- gps.encode(ss.read());
- } while (millis() - start < ms);
- }
- static void printFloat(float val, bool valid, int len, int prec)
- {
- if (!valid)
- {
- while (len-- > 1)
- Serial.print('*');
- Serial.print(' ');
- }
- else
- {
- Serial.print(val, prec);
- int vi = abs((int)val);
- int flen = prec + (val < 0.0 ? 2 : 1); // . and -
- flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
- for (int i=flen; i<len; ++i)
- Serial.print(' ');
- }
- smartDelay(0);
- }
- static void printInt(unsigned long val, bool valid, int len)
- {
- char sz[32] = "*****************";
- if (valid)
- sprintf(sz, "%ld", val);
- sz[len] = 0;
- for (int i=strlen(sz); i<len; ++i)
- sz[i] = ' ';
- if (len > 0)
- sz[len-1] = ' ';
- Serial.print(sz);
- smartDelay(0);
- }
- static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
- {
- if (!d.isValid())
- {
- Serial.print(F("********** "));
- }
- else
- {
- char sz[32];
- sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
- Serial.print(sz);
- }
- if (!t.isValid())
- {
- Serial.print(F("******** "));
- }
- else
- {
- char sz[32];
- sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
- Serial.print(sz);
- }
- printInt(d.age(), d.isValid(), 5);
- smartDelay(0);
- }
- static void printStr(const char *str, int len)
- {
- int slen = strlen(str);
- for (int i=0; i<len; ++i)
- Serial.print(i<slen ? str[i] : ' ');
- smartDelay(0);
- }
- void dit()
- {
- analogWrite(tonePin,128);
- delay(dotPeriod);
- analogWrite(tonePin,0);
- delay(relaxTime);
- }
- void dah()
- {
- analogWrite(tonePin,128);
- delay(dashPeriod);
- digitalWrite(tonePin,LOW);
- analogWrite(tonePin,0);
- delay(relaxTime);
- }
- void playLetter(char x)
- {
- switch (x) {
- // dit tree
- case 'E':
- dit(); return;
- case 'A':
- dit(); dah(); return;
- case 'W':
- dit(); dah(); dah();return;
- case 'R':
- dit(); dah(); dit();return;
- case 'J':
- dit(); dah(); dah(); dah(); return;
- case 'P':
- dit(); dah(); dah(); dit(); return;
- case 'L':
- dit(); dah(); dit(); dit();return;
- case 'I':
- dit(); dit(); return;
- case 'U':
- dit(); dit(); dah(); return;
- case 'S':
- dit(); dit(); dit(); return;
- case 'F':
- dit(); dit(); dah(); dit(); return;
- case 'V':
- dit(); dit(); dit(); dah(); return;
- case 'H':
- dit(); dit(); dit(); dit(); return;
- // dah tree
- case 'T':
- dah(); return;
- case 'M':
- dah(); dah();return;
- case 'O':
- dah(); dah(); dah();return;
- case 'G':
- dah(); dah(); dit();return;
- case 'Q':
- dah(); dah(); dit(); dah(); return;
- case 'Z':
- dah(); dah(); dit(); dit(); return;
- case 'N':
- dah(); dit(); return;
- case 'K':
- dah(); dit(); dah(); return;
- case 'Y':
- dah(); dit(); dah(); dah(); return;
- case 'C':
- dah(); dit(); dah(); dit(); return;
- case 'D':
- dah(); dit(); dit(); return;
- case 'X':
- dah(); dit(); dit(); dah(); return;
- case 'B':
- dah(); dit(); dit(); dit(); return;
- case 1:
- dit(); dah(); dah(); dah(); dah(); return;
- case 2:
- dit(); dit(); dah(); dah(); dah(); return;
- case 3:
- dit(); dit(); dit(); dah(); dah(); return;
- case 4:
- dit(); dit(); dit(); dit(); dah(); return;
- case 5:
- dit(); dit(); dit(); dit(); dit(); return;
- case 6:
- dah(); dit(); dit(); dit(); dit(); return;
- case 7:
- dah(); dah(); dit(); dit(); dit(); return;
- case 8:
- dah(); dah(); dah(); dit(); dit(); return;
- case 9:
- dah(); dah(); dah(); dah(); dit(); return;
- case 0: // Zero
- dah(); dah(); dah(); dah(); dah(); return;
- case ' ':
- delay(wordSpace); return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement